From 5a00f8f58a18c87f2a7b9815d832c0beef7b9bff Mon Sep 17 00:00:00 2001 From: Alexander Adolf Date: Fri, 4 Jun 2021 01:41:56 +0200 Subject: [PATCH] Cannot Use __git_ps1 in normal mode for zsh vcs_info When using the __git_ps1 shell function in normal mode (i.e. passing it a single argument) in conjunction with the vcs_info library under zsh, the percent character ('%'), used to indicate untracked objects, breaks the rendering ('%f' is no longer recognised as ending the colour code, but appears verbatim in the prompt). This is because using vcs_info requires the PROMPT_SUBST option to be set in zsh, but which changes the handling of percent characters. When PROMPT_SUBST is in effect, one additional 'level' of percent signs is consumed by the prompt substitution, and to get the desired effect (resulting in a single, verbatim percent character in the prompt), four percent signs need to be inserted. This commit changes the way the needed percent character(s) to indicate untracked objects are inserted when running under zsh, depending on whether the PROMPT_SUBST option is in effect or not. --- contrib/completion/git-prompt.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index db7c0068fb..f8d19139b6 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -540,7 +540,11 @@ __git_ps1 () [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] && git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null then - u="%${ZSH_VERSION+%}" + if [ $ps1_expanded = yes ]; then + u="%${ZSH_VERSION+%%%}" + else + u="%${ZSH_VERSION+%}" + fi fi if [ -n "${GIT_PS1_COMPRESSSPARSESTATE-}" ] && -- 2.31.1