Define functions based on zshell version

Rather than figuring out the shell version inside the precmd functions, do the
computation once at startup and define precmd functions based on that. Just an
ever so slight increase in performance.

...cause I'm a nerd. :)
This commit is contained in:
Eryn Wells 2012-10-10 14:07:22 -07:00
parent 738cadb50f
commit ab3f017c03

43
zshrc
View file

@ -36,16 +36,30 @@ precmd_xterm_title()
[[ -n "$DISPLAY" ]] && print -Pn "\e]2;%n@%m\a"
}
precmd_prompt()
{
if (is-at-least '4.3.7'); then
isroot="%(!.%B%F{red}%#%F{default}%b.%#)"
else
isroot="%(!.%{$fg_bold[red]%}%#%{$reset_color%}.%#)"
fi
PROMPT_LINE="$isroot "
precmd_prompt() {
PROMPT_LINE="%(!.%B%F{red}%#%F{default}%b.%#) "
}
precmd_flags_rprompt() {
# background jobs
RPROMPT="%(1j.[%B%F{magenta}%j%F{default}%b].)"
# exit status
RPROMPT+="%(0?..[%B%F{red}%?%F{default}%b])"
}
else
precmd_prompt() {
PROMPT_LINE="%(!.%{$fg_bold[red]%}%#%{$reset_color%}.%#) "
}
precmd_flags_rprompt() {
# background jobs
RPROMPT="%(1j.[%{$fg_bold[magenta]%}%j%{$reset_color%}].)"
# exit status
RPROMPT+="%(0?..[%{$fg_bold[red]%}%?%{$reset_color%}])"
}
fi
precmd_info()
{
PROMPT_NAME='%B%F{magenta}%n%f%b'
@ -64,21 +78,6 @@ precmd_git_branch()
fi
}
precmd_flags_rprompt()
{
local bgjob
local cmdstat
if (is-at-least '4.3.7'); then
bgjob="%(1j.[%B%F{magenta}%j%F{default}%b].)"
cmdstat="%(0?..[%B%F{red}%?%F{default}%b])"
else
bgjob="%(1j.[%{$fg_bold[magenta]%}%j%{$reset_color%}].)"
cmdstat="%(0?..[%{$fg_bold[red]%}%?%{$reset_color%}])"
fi
RPROMPT="$cmdstat$bgjob"
}
precmd_assemble_prompt()
{
local p="$PROMPT_NAME "