Skip to content

Instantly share code, notes, and snippets.

@emilyhorsman
Created October 4, 2015 17:43
Show Gist options
  • Save emilyhorsman/830c04502d80b55ceaa3 to your computer and use it in GitHub Desktop.
Save emilyhorsman/830c04502d80b55ceaa3 to your computer and use it in GitHub Desktop.
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' formats "%F{175}%b%f (%s) "
git_object_count() {
git count-objects -v | cut -d: -f 2 | paste -sd+ - | bc
}
count_matches() {
echo $1 | grep $2 | wc -l | sed -e 's/^[ \t]*//'
}
vcs_prompt() {
git_prompt="${vcs_info_msg_0_}"
# If we're in a git repo with an object count less than our threshold
# (checking the status of large repos is too slow).
: ${GIT_OBJECT_THRESHOLD:=40000}
if [[ $git_prompt =~ "(git)" ]] && [ $(git_object_count) -le $GIT_OBJECT_THRESHOLD ]
then
ss=$(git status --short)
staged=$(count_matches $ss "^[MDA]")
[ $staged -ne 0 ] && git_prompt="$git_prompt%F{green}${staged}S%f "
unstaged=$(count_matches $ss "^.[MD]")
[ $unstaged -ne 0 ] && git_prompt="$git_prompt%F{red}${unstaged}U%f "
untracked=$(count_matches $ss "^??")
[ $untracked -ne 0 ] && git_prompt="$git_prompt%F{blue}$untracked?%f"
fi
echo $git_prompt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment