Merge branch '/dritter/mercurial_support' into staging branch.

pull/22/head
Ben Hilburn 10 years ago
commit 07e4508706

@ -25,20 +25,28 @@ CURRENT_BG='NONE'
# bizarre characters below, your fonts are not correctly installed. # bizarre characters below, your fonts are not correctly installed.
LEFT_SEGMENT_SEPARATOR='' LEFT_SEGMENT_SEPARATOR=''
RIGHT_SEGMENT_SEPARATOR='' RIGHT_SEGMENT_SEPARATOR=''
VCS_UNSTAGED_ICON='●'
VCS_STAGED_ICON='✚'
################################################################ ################################################################
# vcs_info settings for git # vcs_info settings for git
################################################################ ################################################################
local VCS_WORKDIR_DIRTY=false
setopt prompt_subst setopt prompt_subst
autoload -Uz vcs_info autoload -Uz vcs_info
zstyle ':vcs_info:*' stagedstr " %F{black}%f" zstyle ':vcs_info:*' stagedstr " %F{black}$VCS_STAGED_ICON%f"
zstyle ':vcs_info:git:*' unstagedstr " %F{black}●%f" zstyle ':vcs_info:*' unstagedstr " %F{black}$VCS_UNSTAGED_ICON%f"
zstyle ':vcs_info:git*' actionformats " %b %F{red}| %a%f" zstyle ':vcs_info:*' actionformats " %b %F{red}| %a%f"
zstyle ':vcs_info:git*' formats " %b%c%u%m" zstyle ':vcs_info:*' formats " %b%c%u%m"
zstyle ':vcs_info:*' check-for-changes true zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-aheadbehind git-remotebranch git-tagname zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-aheadbehind git-remotebranch git-tagname
zstyle ':vcs_info:*' enable git zstyle ':vcs_info:hg*' get-revision true # If false, the dirty-check won't work in mercurial
zstyle ':vcs_info:hg*:*' branchformat "%b" # only show branch
zstyle ':vcs_info:*' enable git hg
## Debugging
#zstyle ':vcs_info:*+*:*' debug true
################################################################ ################################################################
# Prompt Segment Constructors # Prompt Segment Constructors
@ -95,19 +103,18 @@ prompt_context() {
fi fi
} }
# Git: branch/detached head, dirty status # branch/detached head, dirty status
prompt_git() { prompt_vcs() {
local dirty local vcs_prompt="${vcs_info_msg_0_}"
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then if [[ -n $vcs_prompt ]]; then
dirty=$(parse_git_dirty) if ( $VCS_WORKDIR_DIRTY ); then
if [[ -n $dirty ]]; then
$1_prompt_segment yellow black $1_prompt_segment yellow black
else else
$1_prompt_segment green black $1_prompt_segment green black
fi fi
echo -n "${vcs_info_msg_0_}" echo -n "$vcs_prompt"
fi fi
} }
@ -160,6 +167,14 @@ function +vi-git-tagname() {
[[ -n ${tag} ]] && hook_com[branch]=" %F{black}${tag}%f" [[ -n ${tag} ]] && hook_com[branch]=" %F{black}${tag}%f"
} }
function +vi-vcs-detect-changes() {
if [[ -n ${hook_com[staged]} ]] || [[ -n ${hook_com[unstaged]} ]]; then
VCS_WORKDIR_DIRTY=true
else
VCS_WORKDIR_DIRTY=false
fi
}
# Dir: current working directory # Dir: current working directory
prompt_dir() { prompt_dir() {
$1_prompt_segment blue black '%~' $1_prompt_segment blue black '%~'
@ -237,7 +252,7 @@ prompt_rbenv() {
# Main prompt # Main prompt
build_left_prompt() { build_left_prompt() {
if (( ${#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS} == 0 )); then if (( ${#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS} == 0 )); then
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir git) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs)
fi fi
for element in $POWERLEVEL9K_LEFT_PROMPT_ELEMENTS; do for element in $POWERLEVEL9K_LEFT_PROMPT_ELEMENTS; do
@ -261,7 +276,11 @@ build_right_prompt() {
} }
# Create the prompts # Create the prompts
precmd() { vcs_info } precmd() {
vcs_info
# Add a static hook to examine staged/unstaged changes.
vcs_info_hookadd set-message vcs-detect-changes
}
PROMPT='%{%f%b%k%}$(build_left_prompt) ' PROMPT='%{%f%b%k%}$(build_left_prompt) '
RPROMPT='%{%f%b%k%}$(build_right_prompt)%{$reset_color%}' RPROMPT='%{%f%b%k%}$(build_right_prompt)%{$reset_color%}'

Loading…
Cancel
Save