Skip to content

Instantly share code, notes, and snippets.

@cadwallion
Created December 30, 2011 16:55
Show Gist options
  • Save cadwallion/1540590 to your computer and use it in GitHub Desktop.
Save cadwallion/1540590 to your computer and use it in GitHub Desktop.
Using branch coloration to indicate dirty/clean in oh-my-zsh
PROMPT='%{$fg_bold[red]%}%m%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
RPROMPT='%{$reset_color%} %{$fg[yellow]%}$(todo_prompt) %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="(%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[blue]%})%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}"
# get the name of the branch we are on
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$ZSH_THEME_GIT_PROMPT_PREFIX$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
# Checks if working tree is dirty
parse_git_dirty() {
ref=$(git symbolic-ref HEAD 2> /dev/null)
if [[ -n $(git status -s --ignore-submodules=dirty 2> /dev/null) ]]; then
echo "$ZSH_THEME_GIT_PROMPT_DIRTY${ref#refs/heads/}"
else
echo "$ZSH_THEME_GIT_PROMPT_CLEAN${ref#refs/heads/}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment