Skip to content

Instantly share code, notes, and snippets.

@emptyset
Created December 14, 2014 18:53
Show Gist options
  • Save emptyset/cfbc03554bd1c4d4680b to your computer and use it in GitHub Desktop.
Save emptyset/cfbc03554bd1c4d4680b to your computer and use it in GitHub Desktop.
sample code for git branch on prompt (zsh) - copied from some source elsewhere; sorry unable to remember to give credit
# git branch display
git_prompt()
{
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git branch 2> /dev/null | sed -n '/^\*/s/^\* //p')
if git diff --quiet 2> /dev/null >&2; then
git_color="$fg_no_bold[green]"
else
git_color="$fg_no_bold[red]"
fi
echo ":%{$git_color%}$git_branch%{$reset_color%}"
}
autoload -U promptinit
promptinit
autoload colors zsh/terminfo
colors
setopt prompt_subst
# not sure this is needed for osx
case $TERM in
*xterm*)
precmd () {print -Pn "\e]0;%n@%M: %~\a"}
;;
esac
# customize to your content
PROMPT='[%B%{$fg_bold[green]%}%1d%{$reset_color%}%b$(git_prompt)] '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment