Skip to content

Instantly share code, notes, and snippets.

@jcartledge
Created September 30, 2012 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcartledge/3806703 to your computer and use it in GitHub Desktop.
Save jcartledge/3806703 to your computer and use it in GitHub Desktop.
My git prompt is better than any other one I've seen anywhere.
# prompt
function _git_prompt() {
local git_status="`git status -unormal 2>&1`"
if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
if [[ "$git_status" =~ Changed\ but\ not\ updated ]] || [[ "$git_status" =~ Untracked\ files ]] || [[ "$git_status" =~ Changes\ not\ staged ]] || [[ "$git_status" =~ Unmerged\ paths ]]; then
local color="0;31" # red
elif [[ "$git_status" =~ Changes\ to\ be\ committed ]]; then
local color="0;32"
else
local color="1;32"
fi
echo -n '\[\033['$color'm\]$(__git_ps1)\[\033[0m\]'
fi
}
function _prompt_command() {
PS1='\w'"`_git_prompt`"'\$\[\e[0m\] ';fi;
}
PROMPT_COMMAND=_prompt_command
# vcs_info for prompt
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git*' check-for-changes true
zstyle ':vcs_info:git*' use-prompt-escapes true
zstyle ':vcs_info:git*' stagedstr "%{$fg_no_bold[green]%}"
zstyle ':vcs_info:git*' unstagedstr "%{$fg_no_bold[red]%}"
precmd() {
if [[ -z $(git ls-files --other --exclude-standard -- $(git rev-parse --show-cdup 2>/dev/null) 2>/dev/null) ]] {
untracked=''
} else {
untracked="%{$fg_no_bold[red]%}"
}
zstyle ':vcs_info:git*' formats "%{$fg_bold[green]%}%c%u$untracked(%b)%{$reset_color%}"
zstyle ':vcs_info:git*' actionformats "%{$fg_bold[green]%}%c%u$untracked(%a|%b)%{$reset_color%}"
vcs_info
}
setopt prompt_subst
# Prompt
PROMPT='%~ ${vcs_info_msg_0_}$ '
RPROMPT='$(vi_mode_prompt_info) %{$fg_bold[green]%}$(~/.rvm/bin/rvm-prompt)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment