From f705b38ac0893eab73c1da6de003558dd6f898ce Mon Sep 17 00:00:00 2001 From: Bernd Stroessenreuther Date: Thu, 17 May 2018 18:18:44 +0200 Subject: [PATCH 1/5] zshrc: making more information about your VCS status available in the prompt if CWD is under version control You get * a "!!" if you have modified files (not yet added) * a "C" if you have added files, but not yet committed * (for now git only) a "U" if you have untracked files * (git only) a "S" plus a number indicating the stash length if you added something to you stashing area (git stash) * (git only) a "P" plus a number indicating the number of pending commits if you have commits not yet pushed to upstream --- etc/zsh/zshrc | 63 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 53af394d..58f67099 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -1892,15 +1892,25 @@ 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" + format "(%s%)-[%b%u%c%m] " "zsh: %r" + actionformat "(%s%)-[%b%u%c%m|%a] " "zsh: %r" rev-branchformat "%b:%r" + stagedstr "|C" + unstagedstr "|!!" + untracked_append_string "|U" + stashlength_append_string "|S" + push_pending_append_string "|P" ) 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} " + format "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b%u%c%m${MAGENTA}]${NO_COLOR} " + actionformat "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b%u%c%m${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOR} " rev-branchformat "%b${RED}:${YELLOW}%r" + stagedstr "${YELLOW}|${RED}C${NO_COLOR}" + unstagedstr "${YELLOW}|${RED}!!${NO_COLOR}" + untracked_append_string "${YELLOW}|${RED}U" + stashlength_append_string "${YELLOW}|${RED}S" + push_pending_append_string "${YELLOW}|${RED}P" ) typeset GRML_VCS_COLOUR_MODE=xxx @@ -1923,20 +1933,65 @@ function grml_vcs_info_set_formats () { AF=${grml_vcs_coloured_formats[actionformat]} F=${grml_vcs_coloured_formats[format]} BF=${grml_vcs_coloured_formats[rev-branchformat]} + ST=${grml_vcs_coloured_formats[stagedstr]} + UN=${grml_vcs_coloured_formats[unstagedstr]} + UNTRACKED_APPEND_STRING=${grml_vcs_coloured_formats[untracked_append_string]} + STASHLENGTH_APPEND_STRING=${grml_vcs_coloured_formats[stashlength_append_string]} + PUSH_PENDING_APPEND_STRING=${grml_vcs_coloured_formats[push_pending_append_string]} 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]} + ST=${grml_vcs_plain_formats[stagedstr]} + UN=${grml_vcs_plain_formats[unstagedstr]} + UNTRACKED_APPEND_STRING=${grml_vcs_plain_formats[untracked_append_string]} + STASHLENGTH_APPEND_STRING=${grml_vcs_plain_formats[stashlength_append_string]} + PUSH_PENDING_APPEND_STRING=${grml_vcs_plain_formats[push_pending_append_string]} GRML_VCS_COLOUR_MODE=plain fi + # configuring vcs_info (especially for git) according to + # http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Version-Control-Information + zstyle ':vcs_info:*' check-for-changes true + #zstyle ':vcs_info:*' debug true + zstyle ':vcs_info:*' stagedstr "$ST" + zstyle ':vcs_info:*' unstagedstr "$UN" zstyle ':vcs_info:*' actionformats "$AF" "zsh: %r" zstyle ':vcs_info:*' formats "$F" "zsh: %r" zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "$BF" + zstyle ':vcs_info:git+set-message:*' hooks git_more_info return 0 } +function +vi-git_more_info() { + local UNTRACKED_APPEND="" + local STASHLENGTH_APPEND="" + local PUSH_PENDING_APPEND="" + + LANG=C git status 2>&1 | grep "Untracked files:" > /dev/null + if [[ $? -eq 0 ]]; then + UNTRACKED_APPEND=${UNTRACKED_APPEND_STRING} + fi + + local STASHLENGTH=$(LANG=C git stash list 2> /dev/null | wc -l) + if [[ $STASHLENGTH -gt 0 ]]; then + STASHLENGTH_APPEND="${STASHLENGTH_APPEND_STRING}${STASHLENGTH}" + fi + + local COMMITS_TO_PUSH=0 + if [[ $(LANG=C git status 2>/dev/null | grep "Your branch is ahead") =~ " by ([0-9]+) commit" ]]; then + COMMITS_TO_PUSH=$MATCH + COMMITS_TO_PUSH=${COMMITS_TO_PUSH:s/ by /} + COMMITS_TO_PUSH=${COMMITS_TO_PUSH:s/ commit/} + fi + if [[ $COMMITS_TO_PUSH -gt 0 ]]; then + PUSH_PENDING_APPEND="${PUSH_PENDING_APPEND_STRING}${COMMITS_TO_PUSH}" + fi + + hook_com[misc]="${UNTRACKED_APPEND}${STASHLENGTH_APPEND}${PUSH_PENDING_APPEND}" + 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. if [[ "$TERM" == dumb ]] ; then From 65693ca2fcbd0138f59f19eac8f7067105b5b055 Mon Sep 17 00:00:00 2001 From: Bernd Stroessenreuther Date: Fri, 9 Nov 2018 16:21:35 +0100 Subject: [PATCH 2/5] zshrc: making extended VCS info available without using check-for-changes check-for-changes might have performace issues in some extreme cases, so providing same info as in f705b38ac0893eab73c1da6de003558dd6f898ce but without using this option --- etc/zsh/zshrc | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 58f67099..dfb73d77 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -1892,22 +1892,22 @@ typeset -A grml_vcs_coloured_formats typeset -A grml_vcs_plain_formats grml_vcs_plain_formats=( - format "(%s%)-[%b%u%c%m] " "zsh: %r" - actionformat "(%s%)-[%b%u%c%m|%a] " "zsh: %r" + format "(%s%)-[%b%m] " "zsh: %r" + actionformat "(%s%)-[%b%m|%a] " "zsh: %r" rev-branchformat "%b:%r" - stagedstr "|C" - unstagedstr "|!!" + added_append_string "|C" + modified_append_string "|!!" untracked_append_string "|U" stashlength_append_string "|S" push_pending_append_string "|P" ) grml_vcs_coloured_formats=( - format "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b%u%c%m${MAGENTA}]${NO_COLOR} " - actionformat "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b%u%c%m${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOR} " + format "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b%m${MAGENTA}]${NO_COLOR} " + actionformat "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b%m${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOR} " rev-branchformat "%b${RED}:${YELLOW}%r" - stagedstr "${YELLOW}|${RED}C${NO_COLOR}" - unstagedstr "${YELLOW}|${RED}!!${NO_COLOR}" + added_append_string "${YELLOW}|${RED}C${NO_COLOR}" + modified_append_string "${YELLOW}|${RED}!!${NO_COLOR}" untracked_append_string "${YELLOW}|${RED}U" stashlength_append_string "${YELLOW}|${RED}S" push_pending_append_string "${YELLOW}|${RED}P" @@ -1933,8 +1933,8 @@ function grml_vcs_info_set_formats () { AF=${grml_vcs_coloured_formats[actionformat]} F=${grml_vcs_coloured_formats[format]} BF=${grml_vcs_coloured_formats[rev-branchformat]} - ST=${grml_vcs_coloured_formats[stagedstr]} - UN=${grml_vcs_coloured_formats[unstagedstr]} + ADDED_APPEND_STRING=${grml_vcs_coloured_formats[added_append_string]} + MODIFIED_APPEND_STRING=${grml_vcs_coloured_formats[modified_append_string]} UNTRACKED_APPEND_STRING=${grml_vcs_coloured_formats[untracked_append_string]} STASHLENGTH_APPEND_STRING=${grml_vcs_coloured_formats[stashlength_append_string]} PUSH_PENDING_APPEND_STRING=${grml_vcs_coloured_formats[push_pending_append_string]} @@ -1943,8 +1943,8 @@ function grml_vcs_info_set_formats () { AF=${grml_vcs_plain_formats[actionformat]} F=${grml_vcs_plain_formats[format]} BF=${grml_vcs_plain_formats[rev-branchformat]} - ST=${grml_vcs_plain_formats[stagedstr]} - UN=${grml_vcs_plain_formats[unstagedstr]} + ADDED_APPEND_STRING=${grml_vcs_plain_formats[added_append_string]} + MODIFIED_APPEND_STRING=${grml_vcs_plain_formats[modified_append_string]} UNTRACKED_APPEND_STRING=${grml_vcs_plain_formats[untracked_append_string]} STASHLENGTH_APPEND_STRING=${grml_vcs_plain_formats[stashlength_append_string]} PUSH_PENDING_APPEND_STRING=${grml_vcs_plain_formats[push_pending_append_string]} @@ -1953,10 +1953,7 @@ function grml_vcs_info_set_formats () { # configuring vcs_info (especially for git) according to # http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Version-Control-Information - zstyle ':vcs_info:*' check-for-changes true #zstyle ':vcs_info:*' debug true - zstyle ':vcs_info:*' stagedstr "$ST" - zstyle ':vcs_info:*' unstagedstr "$UN" zstyle ':vcs_info:*' actionformats "$AF" "zsh: %r" zstyle ':vcs_info:*' formats "$F" "zsh: %r" zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "$BF" @@ -1965,11 +1962,25 @@ function grml_vcs_info_set_formats () { } function +vi-git_more_info() { + local ADDED_APPEND="" + local MODIFIED_APPEND="" local UNTRACKED_APPEND="" local STASHLENGTH_APPEND="" local PUSH_PENDING_APPEND="" - LANG=C git status 2>&1 | grep "Untracked files:" > /dev/null + local GIT_STATUS=$(LANG=C git status 2>&1) + + echo $GIT_STATUS | grep "new file:" > /dev/null + if [[ $? -eq 0 ]]; then + ADDED_APPEND=${ADDED_APPEND_STRING} + fi + + echo $GIT_STATUS | grep "modified:" > /dev/null + if [[ $? -eq 0 ]]; then + MODIFIED_APPEND=${MODIFIED_APPEND_STRING} + fi + + echo $GIT_STATUS | grep "Untracked files:" > /dev/null if [[ $? -eq 0 ]]; then UNTRACKED_APPEND=${UNTRACKED_APPEND_STRING} fi @@ -1980,7 +1991,7 @@ function +vi-git_more_info() { fi local COMMITS_TO_PUSH=0 - if [[ $(LANG=C git status 2>/dev/null | grep "Your branch is ahead") =~ " by ([0-9]+) commit" ]]; then + if [[ $(echo $GIT_STATUS | grep "Your branch is ahead") =~ " by ([0-9]+) commit" ]]; then COMMITS_TO_PUSH=$MATCH COMMITS_TO_PUSH=${COMMITS_TO_PUSH:s/ by /} COMMITS_TO_PUSH=${COMMITS_TO_PUSH:s/ commit/} @@ -1989,7 +2000,7 @@ function +vi-git_more_info() { PUSH_PENDING_APPEND="${PUSH_PENDING_APPEND_STRING}${COMMITS_TO_PUSH}" fi - hook_com[misc]="${UNTRACKED_APPEND}${STASHLENGTH_APPEND}${PUSH_PENDING_APPEND}" + hook_com[misc]="${ADDED_APPEND}${MODIFIED_APPEND}${UNTRACKED_APPEND}${STASHLENGTH_APPEND}${PUSH_PENDING_APPEND}" return 0 } # Change vcs_info formats for the grml prompt. The 2nd format sets up From ae3b947b74e044d028f439d9f0384c313a5c1c64 Mon Sep 17 00:00:00 2001 From: Bernd Stroessenreuther Date: Tue, 13 Nov 2018 22:01:32 +0100 Subject: [PATCH 3/5] zshrc: making extended VCS info work with elder zsh versions too --- etc/zsh/zshrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index dfb73d77..5052bcdc 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -1967,8 +1967,9 @@ function +vi-git_more_info() { local UNTRACKED_APPEND="" local STASHLENGTH_APPEND="" local PUSH_PENDING_APPEND="" + local GIT_STATUS="" - local GIT_STATUS=$(LANG=C git status 2>&1) + GIT_STATUS=$(LANG=C git status 2>&1) echo $GIT_STATUS | grep "new file:" > /dev/null if [[ $? -eq 0 ]]; then From 2bd10ac4f60563cdde8b069a487be918f7512f01 Mon Sep 17 00:00:00 2001 From: Bernd Stroessenreuther Date: Mon, 5 Aug 2019 19:12:50 +0200 Subject: [PATCH 4/5] zshrc: making extended VCS info easy to switch off --- etc/zsh/zshrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 5052bcdc..d381ae10 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -1962,6 +1962,15 @@ function grml_vcs_info_set_formats () { } function +vi-git_more_info() { + # if you want to disable the extended VCS infos in your prompt + # (e. g. because of lagging prompts in large git repos on old hardware) + # please put 'GRML_EXTENDED_VCS_INFO=0' into your .zshrc.pre + + GRML_EXTENDED_VCS_INFO=${GRML_EXTENDED_VCS_INFO:-1} + if [[ $GRML_EXTENDED_VCS_INFO -eq 0 ]]; then + return 0 + fi + local ADDED_APPEND="" local MODIFIED_APPEND="" local UNTRACKED_APPEND="" From c639e56a81bcf2d0681dafe5281da3e6f6b65014 Mon Sep 17 00:00:00 2001 From: Bernd Stroessenreuther Date: Wed, 21 Aug 2019 22:12:51 +0200 Subject: [PATCH 5/5] zshrc: adding a timeout for extended VCS info too hard impacts by lagging prompts --- etc/zsh/zshrc | 76 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index d381ae10..5c7dc033 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -1900,6 +1900,7 @@ grml_vcs_plain_formats=( untracked_append_string "|U" stashlength_append_string "|S" push_pending_append_string "|P" + unknown_append_string "|?" ) grml_vcs_coloured_formats=( @@ -1911,6 +1912,7 @@ grml_vcs_coloured_formats=( untracked_append_string "${YELLOW}|${RED}U" stashlength_append_string "${YELLOW}|${RED}S" push_pending_append_string "${YELLOW}|${RED}P" + unknown_append_string "${YELLOW}|${RED}?${NO_COLOR}" ) typeset GRML_VCS_COLOUR_MODE=xxx @@ -1938,6 +1940,7 @@ function grml_vcs_info_set_formats () { UNTRACKED_APPEND_STRING=${grml_vcs_coloured_formats[untracked_append_string]} STASHLENGTH_APPEND_STRING=${grml_vcs_coloured_formats[stashlength_append_string]} PUSH_PENDING_APPEND_STRING=${grml_vcs_coloured_formats[push_pending_append_string]} + UNKNOWN_APPEND_STRING=${grml_vcs_coloured_formats[unknown_append_string]} GRML_VCS_COLOUR_MODE=coloured else AF=${grml_vcs_plain_formats[actionformat]} @@ -1948,6 +1951,7 @@ function grml_vcs_info_set_formats () { UNTRACKED_APPEND_STRING=${grml_vcs_plain_formats[untracked_append_string]} STASHLENGTH_APPEND_STRING=${grml_vcs_plain_formats[stashlength_append_string]} PUSH_PENDING_APPEND_STRING=${grml_vcs_plain_formats[push_pending_append_string]} + UNKNOWN_APPEND_STRING=${grml_vcs_plain_formats[unknown_append_string]} GRML_VCS_COLOUR_MODE=plain fi @@ -1963,7 +1967,7 @@ function grml_vcs_info_set_formats () { function +vi-git_more_info() { # if you want to disable the extended VCS infos in your prompt - # (e. g. because of lagging prompts in large git repos on old hardware) + # (e. g. because of lagging prompts in large git repos or on old hardware) # please put 'GRML_EXTENDED_VCS_INFO=0' into your .zshrc.pre GRML_EXTENDED_VCS_INFO=${GRML_EXTENDED_VCS_INFO:-1} @@ -1971,46 +1975,62 @@ function +vi-git_more_info() { return 0 fi + # to avoid lagging prompts in very large git repos or on old hardware + # the expensive git call times out after $GRML_VCS_TIMEOUT seconds + # and the prompt is extended by "|?" + # default is 2 seconds + # you can set your own value by putting into you .zshrc.pre something like + # GRML_VCS_TIMEOUT=4 + GRML_VCS_TIMEOUT=${GRML_VCS_TIMEOUT:-2} + local ADDED_APPEND="" local MODIFIED_APPEND="" local UNTRACKED_APPEND="" local STASHLENGTH_APPEND="" local PUSH_PENDING_APPEND="" + local UNKNOWN_APPEND="" local GIT_STATUS="" + local GIT_STATUS_RC=-1 - GIT_STATUS=$(LANG=C git status 2>&1) + GIT_STATUS=$(LANG=C timeout $GRML_VCS_TIMEOUT git status 2>&1) + GIT_STATUS_RC=$? - echo $GIT_STATUS | grep "new file:" > /dev/null - if [[ $? -eq 0 ]]; then - ADDED_APPEND=${ADDED_APPEND_STRING} - fi + if [[ $GIT_STATUS_RC -eq 124 ]]; then + UNKNOWN_APPEND=${UNKNOWN_APPEND_STRING} + hook_com[misc]="${UNKNOWN_APPEND}" + else + echo $GIT_STATUS | grep "new file:" > /dev/null + if [[ $? -eq 0 ]]; then + ADDED_APPEND=${ADDED_APPEND_STRING} + fi - echo $GIT_STATUS | grep "modified:" > /dev/null - if [[ $? -eq 0 ]]; then - MODIFIED_APPEND=${MODIFIED_APPEND_STRING} - fi + echo $GIT_STATUS | grep "modified:" > /dev/null + if [[ $? -eq 0 ]]; then + MODIFIED_APPEND=${MODIFIED_APPEND_STRING} + fi - echo $GIT_STATUS | grep "Untracked files:" > /dev/null - if [[ $? -eq 0 ]]; then - UNTRACKED_APPEND=${UNTRACKED_APPEND_STRING} - fi + echo $GIT_STATUS | grep "Untracked files:" > /dev/null + if [[ $? -eq 0 ]]; then + UNTRACKED_APPEND=${UNTRACKED_APPEND_STRING} + fi - local STASHLENGTH=$(LANG=C git stash list 2> /dev/null | wc -l) - if [[ $STASHLENGTH -gt 0 ]]; then - STASHLENGTH_APPEND="${STASHLENGTH_APPEND_STRING}${STASHLENGTH}" - fi + local STASHLENGTH=$(LANG=C git stash list 2> /dev/null | wc -l) + if [[ $STASHLENGTH -gt 0 ]]; then + STASHLENGTH_APPEND="${STASHLENGTH_APPEND_STRING}${STASHLENGTH}" + fi - local COMMITS_TO_PUSH=0 - if [[ $(echo $GIT_STATUS | grep "Your branch is ahead") =~ " by ([0-9]+) commit" ]]; then - COMMITS_TO_PUSH=$MATCH - COMMITS_TO_PUSH=${COMMITS_TO_PUSH:s/ by /} - COMMITS_TO_PUSH=${COMMITS_TO_PUSH:s/ commit/} - fi - if [[ $COMMITS_TO_PUSH -gt 0 ]]; then - PUSH_PENDING_APPEND="${PUSH_PENDING_APPEND_STRING}${COMMITS_TO_PUSH}" - fi + local COMMITS_TO_PUSH=0 + if [[ $(echo $GIT_STATUS | grep "Your branch is ahead") =~ " by ([0-9]+) commit" ]]; then + COMMITS_TO_PUSH=$MATCH + COMMITS_TO_PUSH=${COMMITS_TO_PUSH:s/ by /} + COMMITS_TO_PUSH=${COMMITS_TO_PUSH:s/ commit/} + fi + if [[ $COMMITS_TO_PUSH -gt 0 ]]; then + PUSH_PENDING_APPEND="${PUSH_PENDING_APPEND_STRING}${COMMITS_TO_PUSH}" + fi - hook_com[misc]="${ADDED_APPEND}${MODIFIED_APPEND}${UNTRACKED_APPEND}${STASHLENGTH_APPEND}${PUSH_PENDING_APPEND}" + hook_com[misc]="${ADDED_APPEND}${MODIFIED_APPEND}${UNTRACKED_APPEND}${STASHLENGTH_APPEND}${PUSH_PENDING_APPEND}" + fi return 0 } # Change vcs_info formats for the grml prompt. The 2nd format sets up