Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] vcs_info: Escape '%' signs in payloads



Daniel Shahaf wrote on Sun, Feb 05, 2017 at 08:28:13 +0000:
> +++ b/README
> @@ -62,6 +62,15 @@ Note that functions including a non-leading / behave as before,
>  e.g. if `dir/name' is found anywhere under a directory in $fpath it is
>  loaded as a function named `dir/name'.
>  
> +3) vcs_info: When neither a set-patch-format nor a gen-applied-string
> +(resp. gen-unapplied-string) hook is set, vcs_info now '%'-escapes the
> +applied-string (resp. unapplied-string) before interpolating it into the
> +patch-format string, to prevent literal `%' signs in the interpolated
> +value from being interpreted as prompt escape sequences.  If you use
> +${vcs_info_msg_0_} in a context other than the shell prompt, you may need
> +to undo the escaping with:
> +    print -v vcs_info_msg_0_ -Pr -- "${vcs_info_msg_0_}"

Another variant of this: the "Episode II" variant in Misc/vcs_info-examples
expected $vcs_info_msg_0_ to be a literal string, whereas "Episode I"
and "Episode III" expected $vcs_info_msg_0_ to be prompt-escaped.

Since we can't be backwards compatible with both of the different
semantics, I'm voting for breaking the psvar syntax, on the assumption
that it's less widely used.  (so that'd be the lesser of two evils)

The failure mode for people who upgrade to vcs_info 5.4 without applying
the following patch to their dotfiles' precmd functions is that any and
all literal % signs in patch subjects would be doubled; so a patch that
said "10% optimization" would render as "10%% optimization".

Cheers,

Daniel

P.S. Tangent: I've been wondering how many people know that if they put
%m in their actionformats, they can get information about in-progress
rebases into their prompts.  That detail seems to be buried in the
depths of the reference manual...


diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples
index 766eb82..58dd8cf 100644
--- a/Misc/vcs_info-examples
+++ b/Misc/vcs_info-examples
@@ -31,7 +31,7 @@ precmd() {
     psvar=()
 
     vcs_info
-    [[ -n $vcs_info_msg_0_ ]] && psvar[1]="$vcs_info_msg_0_"
+    [[ -n $vcs_info_msg_0_ ]] && print -v 'psvar[1]' -Pr -- "$vcs_info_msg_0_"
 }
 
 # You can now use `%1v' to drop the $vcs_info_msg_0_ contents in your prompt;
diff --git a/README b/README
index 594b6f1..432a35e 100644
--- a/README
+++ b/README
@@ -69,8 +69,11 @@ patch-format string, to prevent literal `%' signs in the interpolated
 value from being interpreted as prompt escape sequences.  If you use
 ${vcs_info_msg_0_} in a context other than the shell prompt, you may need
 to undo the escaping with:
+
     print -v vcs_info_msg_0_ -Pr -- "${vcs_info_msg_0_}"
 
+This is also needed if $vcs_info_msg_0_ is used to set $psvar.
+
 Incompatibilities between 5.0.8 and 5.3
 ----------------------------------------
 



Messages sorted by: Reverse Date, Date, Thread, Author