-
-
Save murilogteixeira/df2b48be4a3b4a22c4e31e9944402f9d to your computer and use it in GitHub Desktop.
zsh: show git repo name, branch in right prompt
This file contains 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
# although StackOverflow has this answer http://stackoverflow.com/a/1128583 | |
# but that code is unreadable, thus I have this (also based on a SO anower: http://stackoverflow.com/a/1128721 ) | |
# get the name of the branch we are on | |
_git_repo_name() { | |
gittopdir=$(git rev-parse --git-dir 2> /dev/null) | |
if [[ "foo$gittopdir" == "foo.git" ]]; then | |
echo `basename $(pwd)` | |
elif [[ "foo$gittopdir" != "foo" ]]; then | |
echo `dirname $gittopdir | xargs basename` | |
fi | |
} | |
_git_branch_name() { | |
git branch 2>/dev/null | awk '/^\*/ { print $2 }' | |
} | |
_git_is_dirty() { | |
git diff --quiet 2> /dev/null || echo '*' | |
} | |
autoload -U colors | |
colors | |
setopt prompt_subst | |
RPROMPT='$(_git_repo_name) $(_git_branch_name) $(_git_is_dirty)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment