Skip to content

Instantly share code, notes, and snippets.

@bamanzi
Created June 27, 2013 09:43
Show Gist options
  • Save bamanzi/5875262 to your computer and use it in GitHub Desktop.
Save bamanzi/5875262 to your computer and use it in GitHub Desktop.
zsh: show git repo name, branch in right prompt
# 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