zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] vcs_info: Escape '%' signs in payloads
Date: Tue, 7 Feb 2017 08:57:33 +0000	[thread overview]
Message-ID: <20170207085733.GA6158@fujitsu.shahaf.local2> (raw)
In-Reply-To: <1486283293-2586-1-git-send-email-danielsh@fujitsu.shahaf.local2>

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
 ----------------------------------------
 


  reply	other threads:[~2017-02-07  9:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-27 15:05 vcs_info: '%' in payloads not escaped Daniel Shahaf
2016-12-27 15:13 ` Daniel Shahaf
2017-01-05 16:07 ` Daniel Shahaf
2017-01-05 16:27   ` Frank Terbeck
2017-01-06  2:21     ` Daniel Shahaf
2017-01-06 10:41       ` Frank Terbeck
2017-01-06 16:40         ` Daniel Shahaf
2017-01-06 17:27           ` Bart Schaefer
2017-01-23 11:04             ` Daniel Shahaf
2017-01-23 18:54               ` Frank Terbeck
2017-02-05  8:28                 ` [PATCH] vcs_info: Escape '%' signs in payloads Daniel Shahaf
2017-02-07  8:57                   ` Daniel Shahaf [this message]
2017-01-06 15:55   ` vcs_info: '%' in payloads not escaped Bart Schaefer
2017-01-06 16:49     ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170207085733.GA6158@fujitsu.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).