Skip to content

Instantly share code, notes, and snippets.

@sputnick-dev
Created January 3, 2016 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sputnick-dev/686f9b57a157df8b94b4 to your computer and use it in GitHub Desktop.
Save sputnick-dev/686f9b57a157df8b94b4 to your computer and use it in GitHub Desktop.
autoload -U colors && colors
setopt prompt_subst
autoload -Uz vcs_info
function +vi-git-untracked() {
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
[[ $(git ls-files --other --directory --exclude-standard | sed q | wc -l | tr -d ' ') == 1 ]] ; then
hook_com[unstaged]+='%F{1}?? %f'
fi
}
# Show remote ref name and number of commits ahead-of or behind
function +vi-git-st() {
local ahead behind remote
local -a gitstatus
# Are we on a remote-tracking branch?
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
--symbolic-full-name 2>/dev/null)/refs\/remotes\/}
if [[ -n ${remote} ]] ; then
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
(( $ahead )) && gitstatus+=( "${c3}+${ahead}${c2}" )
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
(( $behind )) && gitstatus+=( "${c4}-${behind}${c2}" )
hook_com[branch]="${hook_com[branch]}${(j:/:)gitstatus}"
fi
}
# Show count of stashed changes
function +vi-git-stash() {
local -a stashes
if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then
stashes=$(git stash list 2>/dev/null | wc -l)
hook_com[misc]+="%F{white}(%F{1}stash=${stashes}%F{white})"
fi
}
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git*:*' get-revision true
zstyle ':vcs_info:git*:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr 'M'
zstyle ':vcs_info:*' unstagedstr 'M'
zstyle ':vcs_info:*' actionformats '%F{white}(%F{2}%b%F{3}|%F{1}%a%F{white}) '
zstyle ':vcs_info:*' formats '%F{white}(%b%) %F{2}%c%F{3}%u%f%m'
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-stash git-st
zstyle ':vcs_info:*' enable git
#zstyle ':vcs_info:*+*:*' debug true
# same as PROMPT_COMMAND in bash
precmd () { vcs_info }
# conditional on exit code: %(?..%F) on affiche le code de retour uniquement si il est > 0
RPROMPT='%(?..[%F{red}ERROR%F{white}:%F{red}%?%F{white}])'
PROMPT='%F{green}%n%F{orange}@%F{yellow}%m:%F{white}%10~ ${vcs_info_msg_0_} $reset_color
%# '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment