Created
September 29, 2022 13:18
-
-
Save jefflward/183c9332bd09bb65285f7eaa204ed128 to your computer and use it in GitHub Desktop.
Show git details in zsh prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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%# ' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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