about summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2013-07-03 12:46:02 +0100
committerPeter Stephenson <pws@zsh.org>2013-07-03 12:46:02 +0100
commit669c070efe06d1820ccb32adaa6b1512279401ab (patch)
treead4b7f890e6ab3e19c71e4316483eeb61c576ec1 /Functions
parent96c8b2832b4f2237cb78f4616c905d9b4b0cf53e (diff)
downloadzsh-669c070efe06d1820ccb32adaa6b1512279401ab.tar.gz
zsh-669c070efe06d1820ccb32adaa6b1512279401ab.tar.xz
zsh-669c070efe06d1820ccb32adaa6b1512279401ab.zip
31503: zmv improvements for user-specified programs.
-p splits words of commands passed to it.
-P is like -p for when the program doesn't understand the -- convention
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Misc/zmv15
1 files changed, 11 insertions, 4 deletions
diff --git a/Functions/Misc/zmv b/Functions/Misc/zmv
index 4ba664e6d..269fe5ba5 100644
--- a/Functions/Misc/zmv
+++ b/Functions/Misc/zmv
@@ -93,7 +93,11 @@
 #  -p <program>
 #      Call <program> instead of cp, ln or mv.  Whatever it does, it should
 #      at least understand the form '<program> -- <oldname> <newname>',
-#      where <oldname> and <newname> are filenames generated.
+#      where <oldname> and <newname> are filenames generated. <program>
+#      will be split into words.
+#  -P <program>
+#      As -p, but the program doesn't understand the "--" convention.
+#      In this case the file names must already be sane.
 #  -w  Pick out wildcard parts of the pattern, as described above, and
 #      implicitly add parentheses for referring to them.
 #  -W  Just like -w, with the addition of turning wildcards in the
@@ -123,14 +127,16 @@ setopt extendedglob
 
 local f g args match mbegin mend files action myname tmpf opt exec
 local opt_f opt_i opt_n opt_q opt_Q opt_s opt_M opt_C opt_L 
-local opt_o opt_p opt_v opt_w opt_W MATCH MBEGIN MEND
+local opt_o opt_p opt_P opt_v opt_w opt_W MATCH MBEGIN MEND
 local pat repl errstr fpat hasglobqual opat
 typeset -A from to
 integer stat
 
+local dashes=--
+
 myname=${(%):-%N}
 
-while getopts ":o:p:MCLfinqQsvwW" opt; do
+while getopts ":o:p:P:MCLfinqQsvwW" opt; do
   if [[ $opt = "?" ]]; then
     print -r -- "$myname: unrecognized option: -$OPTARG" >&2
     return 1
@@ -144,6 +150,7 @@ done
 [[ -n $opt_C ]] && action=cp
 [[ -n $opt_L ]] && action=ln
 [[ -n $opt_p ]] && action=$opt_p
+[[ -n $opt_P ]] && action=$opt_P dashes=
 
 if [[ -z $action ]]; then
   action=$myname[-2,-1]
@@ -278,7 +285,7 @@ fi
 
 for f in $files; do
   [[ -z $to[$f] ]] && continue
-  exec=($action ${=opt_o} $opt_s -- $f $to[$f])
+  exec=(${=action} ${=opt_o} $opt_s $dashes $f $to[$f])
   [[ -n $opt_i$opt_n$opt_v ]] && print -r -- ${(q-)exec}
   if [[ -n $opt_i ]]; then
     read -q 'opt?Execute? ' || continue