Skip to content

Instantly share code, notes, and snippets.

@jefflward
Created September 29, 2022 13:18
Show Gist options
  • Save jefflward/183c9332bd09bb65285f7eaa204ed128 to your computer and use it in GitHub Desktop.
Save jefflward/183c9332bd09bb65285f7eaa204ed128 to your computer and use it in GitHub Desktop.
Show git details in zsh prompt
# Configures your prompt to include branch and ahead (↑) and behind (↓) details
# Put this folder in your root folder ~/ next to your .zshrc
setopt prompt_subst
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' formats \
'%F{5}[%F{2}%b%F{5}] %F{2}%c%F{3}%u%f'
# Add up/down arrows after branch name, if there are changes to pull/to push
zstyle ':vcs_info:git+post-backend:*' hooks git-post-backend-updown
+vi-git-post-backend-updown() {
git rev-parse master >/dev/null 2>&1 || return
local -a x; x=( $(git rev-list --left-right --count HEAD...origin ) )
hook_com[branch]+="%f" # end coloring
(( x[2] )) && hook_com[branch]+="↓${x[2]}"
(( x[1] )) && hook_com[branch]+="↑${x[1]}"
return 0
}
precmd () { vcs_info }
PROMPT='%F{5}[%F{2}%n%F{5}] %F{3}%3~ ${vcs_info_msg_0_} %f%# '
# Add the following to your .zshrc
[ -f .gitprompt ] && source .gitprompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment