From ab3f017c0365dd2f149bc28aa9e03779b5613225 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Wed, 10 Oct 2012 14:07:22 -0700 Subject: [PATCH] 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. :) --- zshrc | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/zshrc b/zshrc index 3356813..d82f5f2 100644 --- a/zshrc +++ b/zshrc @@ -36,15 +36,29 @@ 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 " -} +if (is-at-least '4.3.7'); then + 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() { @@ -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 "