From: Frank Terbeck Date: Mon, 23 Jun 2014 23:06:49 +0000 (+0200) Subject: zshrc: Add function to toggle colour codes in vcs_info formats X-Git-Tag: v0.9.6~1 X-Git-Url: http://git.grml.org/?p=grml-etc-core.git;a=commitdiff_plain;h=deeb32aa922bbc8147950eded42e436e5e8c8439 zshrc: Add function to toggle colour codes in vcs_info formats → grml_vcs_info_toggle_colour Documentation included. Signed-off-by: Frank Terbeck --- diff --git a/doc/grmlzshrc.t2t b/doc/grmlzshrc.t2t index f6c62a4..cc7aa65 100644 --- a/doc/grmlzshrc.t2t +++ b/doc/grmlzshrc.t2t @@ -615,6 +615,15 @@ Edit given shell function. : **freload()** Reloads an autoloadable shell function (See autoload in zshbuiltins(1)). +: **grml_vcs_info_toggle_colour()** +Toggles between coloured and uncoloured formats in vcs_info configuration. +This is useful with prompts that break if colour codes are in vcs_info +format expansions (like the `clint' prompt and every other prompt that +uses %v to expand the contents of `$vcs_into_msg_0_'). If you are using +customised vcs_info formats, you shouldn't be using this function, since +it will set all formats to grml's default values (either coloured or plain) +again. + : **hgdi()** Use GNU diff with options -ubwd for mercurial. diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index ce02c95..6533d72 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -1689,21 +1689,61 @@ if zrcautoload vcs_info; then fi fi +typeset -A grml_vcs_coloured_formats +typeset -A grml_vcs_plain_formats + +grml_vcs_plain_formats=( + format "(%s%)-[%b] " "zsh: %r" + actionformat "(%s%)-[%b|%a] " "zsh: %r" + rev-branchformat "%b:%r" +) + +grml_vcs_coloured_formats=( + format "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${MAGENTA}]${NO_COLOR} " + actionformat "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOR} " + rev-branchformat "%b${RED}:${YELLOW}%r" +) + +typeset GRML_VCS_COLOUR_MODE=xxx + +grml_vcs_info_toggle_colour () { + emulate -L zsh + if [[ $GRML_VCS_COLOUR_MODE == plain ]]; then + grml_vcs_info_set_formats coloured + else + grml_vcs_info_set_formats plain + fi + return 0 +} + +grml_vcs_info_set_formats () { + emulate -L zsh + #setopt localoptions xtrace + local mode=$1 AF F BF + if [[ $mode == coloured ]]; then + AF=${grml_vcs_coloured_formats[actionformat]} + F=${grml_vcs_coloured_formats[format]} + BF=${grml_vcs_coloured_formats[rev-branchformat]} + GRML_VCS_COLOUR_MODE=coloured + else + AF=${grml_vcs_plain_formats[actionformat]} + F=${grml_vcs_plain_formats[format]} + BF=${grml_vcs_plain_formats[rev-branchformat]} + GRML_VCS_COLOUR_MODE=plain + fi + + zstyle ':vcs_info:*' actionformats "$AF" "zsh: %r" + zstyle ':vcs_info:*' formats "$F" "zsh: %r" + zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "$BF" + return 0 +} + # Change vcs_info formats for the grml prompt. The 2nd format sets up # $vcs_info_msg_1_ to contain "zsh: repo-name" used to set our screen title. -# TODO: The included vcs_info() version still uses $VCS_INFO_message_N_. -# That needs to be the use of $VCS_INFO_message_N_ needs to be changed -# to $vcs_info_msg_N_ as soon as we use the included version. if [[ "$TERM" == dumb ]] ; then - zstyle ':vcs_info:*' actionformats "(%s%)-[%b|%a] " "zsh: %r" - zstyle ':vcs_info:*' formats "(%s%)-[%b] " "zsh: %r" + grml_vcs_info_set_formats plain else - # these are the same, just with a lot of colors: - zstyle ':vcs_info:*' actionformats "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOR} " \ - "zsh: %r" - zstyle ':vcs_info:*' formats "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${MAGENTA}]${NO_COLOR}%} " \ - "zsh: %r" - zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${RED}:${YELLOW}%r" + grml_vcs_info_set_formats coloured fi # Now for the fun part: The grml prompt themes in `promptsys' mode of operation