Created
October 5, 2013 16:54
-
-
Save flyfire/6843301 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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