X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=5f832c7f27707318041833f80c6ae7179ed83b33;hb=08ab5d927b758f7f3445d0dd57b6f9076d1636ca;hp=ad40c2e4100776ea5132428f8c39d72fe00666ba;hpb=605fb0e77f8abf5d95c6f77f7c9d442296efa403;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index ad40c2e..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 @@ -1194,6 +1200,49 @@ chpwd_functions=( ${chpwd_functions} chpwd_profiles ) fi # is433 +# Prompt setup for grml: + +# set colors for use in prompts (modern zshs allow for the use of %F{red}foo%f +# in prompts to get a red "foo" embedded, but it's good to keep these for +# backwards compatibility). +if zrcautoload colors && colors 2>/dev/null ; then + BLUE="%{${fg[blue]}%}" + RED="%{${fg_bold[red]}%}" + GREEN="%{${fg[green]}%}" + CYAN="%{${fg[cyan]}%}" + MAGENTA="%{${fg[magenta]}%}" + YELLOW="%{${fg[yellow]}%}" + WHITE="%{${fg[white]}%}" + NO_COLOR="%{${reset_color}%}" +else + BLUE=$'%{\e[1;34m%}' + RED=$'%{\e[1;31m%}' + GREEN=$'%{\e[1;32m%}' + CYAN=$'%{\e[1;36m%}' + WHITE=$'%{\e[1;37m%}' + MAGENTA=$'%{\e[1;35m%}' + YELLOW=$'%{\e[1;33m%}' + NO_COLOR=$'%{\e[0m%}' +fi + +# First, the easy ones: PS2..4: + +# secondary prompt, printed when the shell needs more information to complete a +# command. +PS2='\`%_> ' +# selection prompt used within a select loop. +PS3='?# ' +# the execution trace prompt (setopt xtrace). default: '+%N:%i>' +PS4='+%N:%i:%_> ' + +# Some additional features to use with our prompt: +# +# - battery status +# - debian_chroot +# - vcs_info setup and version specific fixes +# - command-not-found handling +# (TODO: This has nothing to do with prompts: move!) + # display battery status on right side of prompt via running 'BATTERY=1 zsh' if [[ $BATTERY -gt 0 ]] ; then if ! check_com -c acpi ; then @@ -1215,25 +1264,10 @@ if [[ $BATTERY -gt 0 ]] ; then fi fi } -# set colors for use in prompts -if zrcautoload colors && colors 2>/dev/null ; then - BLUE="%{${fg[blue]}%}" - RED="%{${fg_bold[red]}%}" - GREEN="%{${fg[green]}%}" - CYAN="%{${fg[cyan]}%}" - MAGENTA="%{${fg[magenta]}%}" - YELLOW="%{${fg[yellow]}%}" - WHITE="%{${fg[white]}%}" - NO_COLOR="%{${reset_color}%}" -else - BLUE=$'%{\e[1;34m%}' - RED=$'%{\e[1;31m%}' - GREEN=$'%{\e[1;32m%}' - CYAN=$'%{\e[1;36m%}' - WHITE=$'%{\e[1;37m%}' - MAGENTA=$'%{\e[1;35m%}' - YELLOW=$'%{\e[1;33m%}' - NO_COLOR=$'%{\e[0m%}' + +# set variable debian_chroot if running in a chroot with /etc/debian_chroot +if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then + debian_chroot=$(cat /etc/debian_chroot) fi # gather version control information for inclusion in a prompt @@ -1284,6 +1318,18 @@ function command_not_found_handler() { return 1 } +# Now for the fun part: The grml prompt themes in `promptsys' mode of operation + +# This actually defines three prompts: +# +# - grml +# - grml-large +# - grml-chroot +# +# They all share the same code and only differ with respect to which items they +# contain. The main source of documentation is the `prompt_grml_help' function +# below, which gets called when the user does this: prompt -h grml + function prompt_grml_help () { cat <<__EOF0__ prompt grml @@ -1358,6 +1404,9 @@ function prompt_grml-large_setup () { grml_prompt_setup grml-large } +# These maps define default tokens and pre-/post-decoration for items to be +# used within the themes. All defaults may be customised in a context sensitive +# matter by using zsh's `zstyle' mechanism. typeset -gA grml_prompt_pre_default \ grml_prompt_post_default \ grml_prompt_token_default @@ -1524,17 +1573,37 @@ function prompt_grml_precmd_worker () { fi } -# set prompt -if zrcautoload promptinit && promptinit 2>/dev/null ; then - promptinit # people should be able to use their favourite prompt +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' # ourselves, since promptinit does not pick them up otherwise. 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 @@ -1561,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}${EXITCODE}${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\\' "$@" @@ -1650,20 +1703,6 @@ preexec () { esac } -EXITCODE="%(?..%?%1v )" -# secondary prompt, printed when the shell needs more information to complete a -# command. -PS2='\`%_> ' -# selection prompt used within a select loop. -PS3='?# ' -# the execution trace prompt (setopt xtrace). default: '+%N:%i>' -PS4='+%N:%i:%_> ' - -# set variable debian_chroot if running in a chroot with /etc/debian_chroot -if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then - debian_chroot=$(cat /etc/debian_chroot) -fi - # 'hash' some often used directories #d# start hash -d deb=/var/cache/apt/archives