agnoster: avoid subshell when rendering prompt
Rather than forking a subshell to print the prompt, construct it incrementally by appending to $PROMPT.
This commit is contained in:
parent
036364c299
commit
3e4bcd1730
@ -56,22 +56,22 @@ prompt_segment() {
|
||||
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
|
||||
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
|
||||
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
|
||||
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
|
||||
PROMPT+=" %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
|
||||
else
|
||||
echo -n "%{$bg%}%{$fg%} "
|
||||
PROMPT+="%{$bg%}%{$fg%} "
|
||||
fi
|
||||
CURRENT_BG=$1
|
||||
[[ -n $3 ]] && echo -n $3
|
||||
[[ -n $3 ]] && PROMPT+=$3
|
||||
}
|
||||
|
||||
# End the prompt, closing any open segments
|
||||
prompt_end() {
|
||||
if [[ -n $CURRENT_BG ]]; then
|
||||
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
|
||||
PROMPT+=" %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
|
||||
else
|
||||
echo -n "%{%k%}"
|
||||
PROMPT+="%{%k%}"
|
||||
fi
|
||||
echo -n "%{%f%}"
|
||||
PROMPT+="%{%f%}"
|
||||
CURRENT_BG=''
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ prompt_git() {
|
||||
zstyle ':vcs_info:*' formats ' %u%c'
|
||||
zstyle ':vcs_info:*' actionformats ' %u%c'
|
||||
vcs_info
|
||||
echo -n "${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
|
||||
PROMPT+="${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -136,15 +136,15 @@ prompt_bzr() {
|
||||
revision=`bzr log | head -n2 | tail -n1 | sed 's/^revno: //'`
|
||||
if [[ $status_mod -gt 0 ]] ; then
|
||||
prompt_segment yellow black
|
||||
echo -n "bzr@"$revision "✚ "
|
||||
PROMPT+="bzr@"$revision "✚ "
|
||||
else
|
||||
if [[ $status_all -gt 0 ]] ; then
|
||||
prompt_segment yellow black
|
||||
echo -n "bzr@"$revision
|
||||
PROMPT+="bzr@"$revision
|
||||
|
||||
else
|
||||
prompt_segment green black
|
||||
echo -n "bzr@"$revision
|
||||
PROMPT+="bzr@"$revision
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -167,7 +167,7 @@ prompt_hg() {
|
||||
# if working copy is clean
|
||||
prompt_segment green black
|
||||
fi
|
||||
echo -n $(hg prompt "☿ {rev}@{branch}") $st
|
||||
PROMPT+=$(hg prompt "☿ {rev}@{branch}") $st
|
||||
else
|
||||
st=""
|
||||
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
|
||||
@ -181,7 +181,7 @@ prompt_hg() {
|
||||
else
|
||||
prompt_segment green black
|
||||
fi
|
||||
echo -n "☿ $rev@$branch" $st
|
||||
PROMPT+="☿ $rev@$branch" $st
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@ -216,6 +216,7 @@ prompt_status() {
|
||||
## Main prompt
|
||||
build_prompt() {
|
||||
RETVAL=$?
|
||||
PROMPT='%{%f%b%k%}'
|
||||
prompt_status
|
||||
prompt_virtualenv
|
||||
prompt_context
|
||||
@ -224,6 +225,8 @@ build_prompt() {
|
||||
prompt_bzr
|
||||
prompt_hg
|
||||
prompt_end
|
||||
PROMPT+=' '
|
||||
}
|
||||
|
||||
PROMPT='%{%f%b%k%}$(build_prompt) '
|
||||
autoload -U add-zsh-hook
|
||||
add-zsh-hook precmd build_prompt
|
||||
|
Loading…
Reference in New Issue
Block a user