{"thread":{"id":"55847","subject":"[PATCH] git-prompt.sh not working with vcs_info under zsh","startedAt":"2021-06-05T15:42:13Z","lastAt":"2021-06-05T15:42:13Z","messageCount":1,"participants":["Alexander Adolf"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"426496","messageId":"d8044e41ed12459c405a9a3be522c0f1@condition-alpha.com","threadId":"55847","inReplyTo":null,"subject":"[PATCH] git-prompt.sh not working with vcs_info under zsh","fromName":"Alexander Adolf","fromEmail":"alexander.adolf@condition-alpha.com","sentAt":"2021-06-04T15:17:09Z","receivedAt":"2021-06-05T15:42:13Z","isPatch":true,"sender":{"key":"alexander.adolf@condition-alpha.com","avatar":null},"body":"Hello,\n\nI discovered and fixed a small glitch in git-prompt.sh in conjunction\nwith zsh's vcs_info library. I prefer using git-prompt.sh through\nvcs_info because it allows me to leverage the support of other version\ncontrol systems provided by vcs_info, and still get the more detailed\ninformation provided by git-prompt.sh. Best-of-both-worlds approach. ;-)\n\nThe issue is that the prompt_subst option (required for using vcs_info)\nbreaks the rendering of the percent character to indicate untracked\nobjects. More details in the attached patch.\n\nFor the curious, here is the relevant snippet from my ~/.zshrc:\n---------------------------- Begin Quote -----------------------------\nsetopt prompt_subst\nautoload -U promptinit; promptinit\nautoload -Uz vcs_info\nzstyle ':vcs_info:*' enable git svn cvs hg\nzstyle ':vcs_info:*' check-for-changes true\nsource ~/.zsh/git-prompt.sh\t# defines __git_ps1()\nGIT_PS1_SHOWCOLORHINTS=\"1\"\t# colors are based on the colored output of \"git status -sb\"\nGIT_PS1_SHOWDIRTYSTATE=\"1\"\t# '*' unstaged and '+' staged changes\nGIT_PS1_SHOWSTASHSTATE=\"1\"\t# '$' if something is stashed\nGIT_PS1_SHOWUNTRACKEDFILES=\"1\"\t# '%' if untracked files exist\nGIT_PS1_SHOWUPSTREAM=('name' 'verbose' 'git')\nfunction git-ps1-wrapper () { reply=\" (%s:$(__git_ps1 '%s'))\" }\nzstyle -e ':vcs_info:git:*' formats       'git-ps1-wrapper'\nzstyle -e ':vcs_info:git:*' actionformats 'git-ps1-wrapper'\nzstyle  ':vcs_info:*'     formats       ' (%s:%b%u%c)'\nzstyle  ':vcs_info:*'     actionformats ' (%s:%b%u%c|%a)'\nprecmd () { vcs_info }\nPROMPT='\n%B%m:%2~%b${vcs_info_msg_0_}\n%B%(!.#.▶)%b '\n----------------------------- End Quote ------------------------------\n\n\nMany thanks, looking forward to your thoughts, and have a great weekend,\n\n  --alexander\n\n\n\n\nFrom 5a00f8f58a18c87f2a7b9815d832c0beef7b9bff Mon Sep 17 00:00:00 2001\nFrom: Alexander Adolf <c-alpha@users.noreply.github.com>\nDate: Fri, 4 Jun 2021 01:41:56 +0200\nSubject: [PATCH] Cannot Use __git_ps1 in normal mode for zsh vcs_info\n\nWhen using the __git_ps1 shell function in normal mode (i.e. passing\nit a single argument) in conjunction with the vcs_info library under\nzsh, the percent character ('%'), used to indicate untracked objects,\nbreaks the rendering ('%f' is no longer recognised as ending the\ncolour code, but appears verbatim in the prompt).\n\nThis is because using vcs_info requires the PROMPT_SUBST option to be\nset in zsh, but which changes the handling of percent characters. When\nPROMPT_SUBST is in effect, one additional 'level' of percent signs is\nconsumed by the prompt substitution, and to get the desired\neffect (resulting in a single, verbatim percent character in the\nprompt), four percent signs need to be inserted.\n\nThis commit changes the way the needed percent character(s) to\nindicate untracked objects are inserted when running under zsh,\ndepending on whether the PROMPT_SUBST option is in effect or not.\n---\n contrib/completion/git-prompt.sh | 6 +++++-\n 1 file changed, 5 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex db7c0068fb..f8d19139b6 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -540,7 +540,11 @@ __git_ps1 ()\n \t\t   [ \"$(git config --bool bash.showUntrackedFiles)\" != \"false\" ] &&\n \t\t   git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null\n \t\tthen\n-\t\t\tu=\"%${ZSH_VERSION+%}\"\n+\t\t\tif [ $ps1_expanded = yes ]; then\n+\t\t\t\tu=\"%${ZSH_VERSION+%%%}\"\n+\t\t\telse\n+\t\t\t\tu=\"%${ZSH_VERSION+%}\"\n+\t\t\tfi\n \t\tfi\n \n \t\tif [ -n \"${GIT_PS1_COMPRESSSPARSESTATE-}\" ] &&\n-- \n2.31.1\n\n"}]}