zshrc/zsh.d/50_vcs.zsh
Paweł Płazieński b7f27f99e5 Move vcs to partial
2024-03-03 20:26:41 +01:00

57 lines
1.9 KiB
Bash

# vim: ft=zsh
if [[ -n $MULTIBYTE_SUPPORTED ]]; then
UNSTAGED_CHARACTER="\ue168"
CHANGES_CHARACTER="\ue16b"
UNTRACKED_CHARACTER="\ue16c"
BRANCH_CHARACTER="\ue822"
REVISION_CHARACTER="\ue821"
AHEAD_CHARACTER="\ue174 "
BEHIND_CHARACTER="\ue175 "
ACTIONS_CHARACTER="\ue831"
else
UNSTAGED_CHARACTER="!"
CHANGES_CHARACTER="*"
UNTRACKED_CHARACTER="?"
BRANCH_CHARACTER="~"
REVISION_CHARACTER="r"
AHEAD_CHARACTER="+"
BEHIND_CHARACTER="-"
ACTIONS_CHARACTER="!"
fi
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git hg svn
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' get-revision true
# these formats are set for PROMPT
zstyle ':vcs_info:*' formats "%s $BRANCH_CHARACTER%b $REVISION_CHARACTER%i%u"
zstyle ':vcs_info:*' actionformats "%s $BRANCH_CHARACTER%b $REVISION_CHARACTER%i%u [%a]"
zstyle ':vcs_info:*' branchformat '%b'
zstyle ':vcs_info:hg*' unstagedstr "$CHANGES_CHARACTER"
zstyle ':vcs_info:hg*' hgrevformat "%r" # default "%r:%h"
zstyle ':vcs_info:git*' formats "$BRANCH_CHARACTER%b%u%c%m" # git is standard
zstyle ':vcs_info:git*' actionformats "$BRANCH_CHARACTER%b%u%c%m $ACTIONS_CHARACTER%a"
zstyle ':vcs_info:git*' unstagedstr " $UNSTAGED_CHARACTER"
zstyle ':vcs_info:git*' stagedstr " $CHANGES_CHARACTER"
zstyle ':vcs_info:git*+set-message:*' hooks git-additional
function +vi-git-additional() {
local ahead behind
local -a branchstatus
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
(($ahead)) && branchstatus+=(" $AHEAD_CHARACTER${ahead}")
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
(($behind)) && branchstatus+=(" $BEHIND_CHARACTER${behind}")
hook_com[misc]="${(j::)branchstatus}"
if [[ $(git rev-parse --is-inside-work-tree 2>/dev/null) == 'true' &&
-n $(git status --porcelain | grep -E '^\?\?' 2>/dev/null | tail -n1) ]]; then
hook_com[unstaged]+=" $UNTRACKED_CHARACTER"
fi
}