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

Re: histsubstpattern in zmv



2023-06-02 11:18:38 +0100, Peter Stephenson:
[...]
> > I can't see any good reason not to enable it.
> 
> Having said that, adding an :S variant isn't particularly difficult
> and is more widely useful.
[...]

Many thanks for that.

I take it that supersedes the other patch and that
histsubstpattern will not be enabled in zmv?

I suppose that any time a new history modifier is introduced,
there's a chance that it may break code that did
$var:that-modifier before. Like echo $hard:SOFT here.

grep -rP '\$\w+(\[[^]]*\])?:S' .

in the source of zsh or oh-my-zsh didn't turn up anything,

grep -rP '\$\w+(\[[^]]*\])?:(?![aAceghlpPqQrstux])\w' .

For occurrences of $var:x or $var[...]:x where x is a word
character that is not one of the currently defined modifiers
turns up a few such as:

./Completion/Zsh/Command/_cd:        alt+=( "path-directories-$elem:directory in $tmpcdpath[$elem]:_path_files -W 'tmpcdpath[$elem]' -/" )
./Completion/Unix/Command/_subversion:        ${args/(#b)(*--file*):arg:/$match[1]:file:_files}

So if we were to add a "f" or "d" or "_" modifier today, it
would break some zsh code supplied with zsh.

May be worth applying the patch below today for future-proofing
and a note in the manual that it's unwise to leave a parameter
expansion un-braced if it's followed by a ":"?

diff --git a/Completion/BSD/Command/_rcctl b/Completion/BSD/Command/_rcctl
index 98e4f9846..457c3eb85 100644
--- a/Completion/BSD/Command/_rcctl
+++ b/Completion/BSD/Command/_rcctl
@@ -46,6 +46,6 @@ case $service in
       '*:argument:'
     ;;
   ${(~j:|:)actions}|disable|enable)
-    _arguments "*:service to $words[2]:_services"
+    _arguments "*:service to ${words[2]}:_services"
     ;;
 esac
diff --git a/Completion/Unix/Command/_ant b/Completion/Unix/Command/_ant
index 7401c7449..36c7c0e89 100644
--- a/Completion/Unix/Command/_ant
+++ b/Completion/Unix/Command/_ant
@@ -79,8 +79,8 @@ case $state in
     compset -P '*:'
     compset -S ':*'
     _alternative \
-      "classpath:$state:_path_files -qS: -g '*.(jar|zip)(-.)'" \
-      "classpath:$state:_path_files -r': ' -/" && ret=0
+      "classpath:${state}:_path_files -qS: -g '*.(jar|zip)(-.)'" \
+      "classpath:${state}:_path_files -r': ' -/" && ret=0
   ;;
   property)
     if compset -P 1 '*='; then
diff --git a/Completion/Unix/Command/_ffmpeg b/Completion/Unix/Command/_ffmpeg
index 1329939cd..e5afdac4f 100644
--- a/Completion/Unix/Command/_ffmpeg
+++ b/Completion/Unix/Command/_ffmpeg
@@ -125,7 +125,7 @@ local -a _ffmpeg_argspecs
                 lastopt_description=${lastopt_description//:/\\:}
                 if [[ $example == filename ]]; then
                     lastopt_takesargs=0
-                    lastopt+=":$lastopt_description:_files"
+                    lastopt+=":${lastopt_description}:_files"
                 elif [[ $lastopt == -[asv]pre ]]; then
                     lastopt_takesargs=0
                     lastopt="*$lastopt"
diff --git a/Completion/Unix/Command/_java b/Completion/Unix/Command/_java
index ff6e82645..b2352df7b 100644
--- a/Completion/Unix/Command/_java
+++ b/Completion/Unix/Command/_java
@@ -438,8 +438,8 @@ classpath|sourcepath|bootstrapclasspath|docletpath)
   compset -P '*:'
   compset -S ':*'
   _alternative \
-    "classpath:$state:_path_files -qS: -g '*.(jar|zip)(-.)'" \
-    "classpath:$state:_path_files -r': ' -/" && return
+    "classpath:${state}:_path_files -qS: -g '*.(jar|zip)(-.)'" \
+    "classpath:${state}:_path_files -r': ' -/" && return
   ;;
 
 extdirs)
diff --git a/Completion/Unix/Command/_subversion b/Completion/Unix/Command/_subversion
index 9a0328dca..ccaf310fa 100644
--- a/Completion/Unix/Command/_subversion
+++ b/Completion/Unix/Command/_subversion
@@ -139,7 +139,7 @@ _svn () {
           ;;
           (commit)
             args=(
-	      ${args/(#b)(*--file*):arg:/$match[1]:file:_files}
+	      ${args/(#b)(*--file*):arg:/${match[1]}:file:_files}
               '*:file: _svn_modified "committable"'
             )
           ;;
@@ -189,7 +189,7 @@ _svn () {
 	    args=(
 	    ':propname:(svn:ignore svn:keywords svn:executable svn:eol-style svn:mime-type svn:externals svn:needs-lock svn:global-ignores svn:auto-props)'
 	    ':propval:->propset_propval'
-	    ${args/(#b)(*--file*):arg:/$match[1]:file:_files}
+	    ${args/(#b)(*--file*):arg:/${match[1]}:file:_files}
 	    '*:path or url: _alternative "files:file:_files" "urls:URL:_svn_urls"'
 	    )
 	  ;;
diff --git a/Completion/Zsh/Command/_cd b/Completion/Zsh/Command/_cd
index 961d121e0..9ca846c8f 100644
--- a/Completion/Zsh/Command/_cd
+++ b/Completion/Zsh/Command/_cd
@@ -73,7 +73,7 @@ else
     if zstyle -t ":completion:${curcontext}:path-directories" separate-sections; then
       local elem
       for ((elem=1; elem <= $#tmpcdpath; elem++)); do
-        alt+=( "path-directories-$elem:directory in $tmpcdpath[$elem]:_path_files -W 'tmpcdpath[$elem]' -/" )
+        alt+=( "path-directories-${elem}:directory in ${tmpcdpath[$elem]}:_path_files -W 'tmpcdpath[$elem]' -/" )
       done
     else
       (( $#tmpcdpath )) &&

-- 
Stephane




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