Skip to content

Instantly share code, notes, and snippets.

@flyfire
Created October 5, 2013 16:54
Show Gist options
  • Select an option

  • Save flyfire/6843301 to your computer and use it in GitHub Desktop.

Select an option

Save flyfire/6843301 to your computer and use it in GitHub Desktop.
directory_name() {
PROMPT_PATH=""
CURRENT=`dirname ${PWD}`
if [[ $CURRENT = / ]]; then
PROMPT_PATH=""
elif [[ $PWD = $HOME ]]; then
PROMPT_PATH=""
else
if [[ -d $(git rev-parse --show-toplevel 2>/dev/null) ]]; then
# We're in a git repo.
BASE=$(basename $(git rev-parse --show-toplevel))
if [[ $PWD = $(git rev-parse --show-toplevel) ]]; then
# We're in the root.
PROMPT_PATH=""
else
# We're not in the root. Display the git repo root.
PROMPT_PATH="%{$fg_bold[magenta]%}${BASE}%{$reset_color%}/"
fi
else
PROMPT_PATH=$(print -P %3~)
PROMPT_PATH="${PROMPT_PATH%/*}/"
fi
echo "%{$fg_bold[cyan]%}${PROMPT_PATH}%{$reset_color%}%{$fg[red]%}%1~%{$reset_color%}"
}
export PROMPT=$'$ $(directory_name) '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment