Created
May 25, 2018 11:14
-
-
Save mika/e30b4e99c338f5d80d7681407708609b to your computer and use it in GitHub Desktop.
zsh with extended vcs_info for git
This file contains 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
## customize vcs_info | |
zstyle ':vcs_info:git*:*' check-for-changes true | |
zstyle ':vcs_info:git*:*' unstagedstr '|U' | |
zstyle ':vcs_info:git*:*' stagedstr '|≠' | |
# enable hooks, requires Zsh >=4.3.11 | |
if [[ $ZSH_VERSION == 4.3.<11->* || $ZSH_VERSION == 4.<4->* || $ZSH_VERSION == <5->* ]] ; then | |
# hook for untracked files | |
+vi-untracked() { | |
if [[ $(git rev-parse --is-inside-work-tree 2>/dev/null) == 'true' ]] && \ | |
[[ -n $(git ls-files --others --exclude-standard) ]] ; then | |
hook_com[staged]+='|☂' | |
fi | |
} | |
# unpushed commits | |
+vi-outgoing() { | |
local gitdir="$(git rev-parse --git-dir 2>/dev/null)" | |
[ -n "$gitdir" ] || return 0 | |
if [ -r "${gitdir}/refs/remotes/git-svn" ] ; then | |
local count=$(git rev-list remotes/git-svn.. 2>/dev/null | wc -l) | |
else | |
local branch="$(cat ${gitdir}/HEAD 2>/dev/null)" | |
branch=${branch##*/heads/} | |
local count=$(git rev-list remotes/origin/${branch}.. 2>/dev/null | wc -l) | |
fi | |
if [[ "$count" -gt 0 ]] ; then | |
hook_com[staged]+="|↑$count" | |
fi | |
} | |
# hook for stashed files | |
+vi-stashed() { | |
if git rev-parse --verify refs/stash &>/dev/null ; then | |
hook_com[staged]+='|s' | |
fi | |
} | |
zstyle ':vcs_info:git*+set-message:*' hooks stashed untracked outgoing | |
fi | |
# required for *formats in vcs_info, see below | |
BLUE="%F{blue}" | |
RED="%F{red}" | |
GREEN="%F{green}" | |
CYAN="%F{cyan}" | |
MAGENTA="%F{magenta}" | |
YELLOW="%F{yellow}" | |
WHITE="%F{white}" | |
NO_COLOR="%f" | |
# extend default vcs_info in prompt | |
zstyle ':vcs_info:*' actionformats "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${YELLOW}|${RED}%a%u%c${MAGENTA}]${NO_COLOR} " "zsh: %r" | |
zstyle ':vcs_info:*' formats "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b%u%c${MAGENTA}]${NO_COLOR}%} " "zsh: %r" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment