From 08ab5d927b758f7f3445d0dd57b6f9076d1636ca Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Tue, 5 Mar 2013 15:06:36 +0100 Subject: [PATCH] zshrc: New prompt: Only enable prompt themes with zsh >= 4.3.7 The themes do use modern features, that require this constraint. The fallback prompt, that was being used when promptsys wasn't available is _way_ more backwards compatible (and will remain like that). Use that fallback in cases of $ZSH_VERSION < 4.3.7 as well. This also means, that the GRMLPROMPT=1 and [[ -n $GRML_CHROOT ]] prompts are not available with shells that old. Version 4.3.7 of zsh was released on 2008-10-28. I think it's reasonable to require ~5 year old software for the full-blown version of a setup. The last stable debian release ships version 4.3.10 and the upcoming release will sport version 4.3.17. Grml ISOs come with version >= 5.0.0. Signed-off-by: Frank Terbeck --- etc/zsh/zshrc | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 5c9af65..5f832c7 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -144,6 +144,12 @@ is433(){ return 1 } +is437(){ + [[ $ZSH_VERSION == 4.3.<7->* || $ZSH_VERSION == 4.<4->* \ + || $ZSH_VERSION == <5->* ]] && return 0 + return 1 +} + is439(){ [[ $ZSH_VERSION == 4.3.<9->* || $ZSH_VERSION == 4.<4->* \ || $ZSH_VERSION == <5->* ]] && return 0 @@ -1567,6 +1573,22 @@ function prompt_grml_precmd_worker () { fi } +grml_prompt_fallback() { + setopt prompt_subst + precmd() { + (( ${+functions[vcs_info]} )) && vcs_info + } + + p0="${RED}%(?..%? )${WHITE}${debian_chroot:+($debian_chroot)}" + p1="${BLUE}%n${NO_COLOR}@%m %40<...<%B%~%b%<< "'${vcs_info_msg_0_}'"%# " + if (( EUID == 0 )); then + PROMPT="${BLUE}${p0}${RED}${p1}" + else + PROMPT="${RED}${p0}${BLUE}${p1}" + fi + unset p0 p1 +} + if zrcautoload promptinit && promptinit 2>/dev/null ; then # Since we define the required functions in here and not in files in # $fpath, we need to stick the theme's name into `$prompt_themes' @@ -1574,7 +1596,14 @@ if zrcautoload promptinit && promptinit 2>/dev/null ; then prompt_themes+=( grml grml-chroot grml-large ) # Also, keep the array sorted... prompt_themes=( "${(@on)prompt_themes}" ) +else + print 'Notice: no promptinit available :(' + grml_prompt_fallback +fi +if is437; then + # The prompt themes use modern features of zsh, that require at least + # version 4.3.7 of the shell. Use the fallback otherwise. if [[ $BATTERY -gt 0 ]]; then zstyle ':prompt:grml:right:setup' items sad-smiley battery add-zsh-hook precmd battery @@ -1601,26 +1630,10 @@ if zrcautoload promptinit && promptinit 2>/dev/null ; then prompt grml fi else - print 'Notice: no promptinit available :(' - - # Support a fallback, in case promptsys isn't available. - setopt prompt_subst - - precmd() { (( ${+functions[vcs_info]} )) && vcs_info; } - - p0="${RED}%(?..%? )${WHITE}${debian_chroot:+($debian_chroot)}" - p1="${BLUE}%n${NO_COLOR}@%m %40<...<%B%~%b%<< "'${vcs_info_msg_0_}'"%# " - if (( EUID == 0 )); then - PROMPT="${BLUE}${p0}${RED}${p1}" - else - PROMPT="${RED}${p0}${BLUE}${p1}" - fi - unset p0 p1 + grml_prompt_fallback fi -# make sure to use right prompt only when not running a command -is41 && setopt transient_rprompt - +# Terminal-title wizardry function ESC_print () { info_print $'\ek' $'\e\\' "$@" -- 2.1.4