zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: zmv with alternative commands
@ 2013-07-03 11:17 Peter Stephenson
  2013-07-03 15:57 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2013-07-03 11:17 UTC (permalink / raw)
  To: Zsh Hackers' List

I wanted to use zmv to "p4 integrate" (think alternatively of "git mv"
--- not the same but should indicate what I'm using zmv for) some files.
I encountered two problems: zmv doesn't split the words of the program
you supply with -p, and also "p4 integrate" doesn't understand a
following "--" to indicate the end of options for the subcommand.  I've
introduced -P for the latter case.

Rather minor, but does change the user interface...

diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index b191e10..a8ddad2 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -3618,7 +3618,7 @@ ifzman(above)\
 ifnzman((noderef(Utilities))).
 )
 findex(zmv)
-item(tt(zmv) [ tt(-finqQsvwW) ] [ -C | -L | -M | -p var(program) ] [ -o var(optstring) ] var(srcpat) var(dest) )(
+item(tt(zmv) [ tt(-finqQsvwW) ] [ -C | -L | -M | -[pP] var(program) ] [ -o var(optstring) ] var(srcpat) var(dest) )(
 Move (usually, rename) files matching the pattern var(srcpat) to
 corresponding files having names of the form given by var(dest), where
 var(srcpat) contains parentheses surrounding patterns which will be
@@ -3663,7 +3663,13 @@ sitem(tt(-p) var(program))(Call var(program) instead of tt(cp), tt(ln) or
 tt(mv).  Whatever it does, it should at least understand the form
 ifzman(`var(program) tt(-)tt(-) var(oldname) var(newname)')\
 ifnzman(example(var(program) tt(-)tt(-) var(oldname) var(newname)))
-where var(oldname) and var(newname) are filenames generated by tt(zmv).)
+where var(oldname) and var(newname) are filenames generated by tt(zmv).
+var(program) will be split into words, so might be e.g. the name
+of an archive tool plus a copy or rename subcommand.)
+sitem(tt(-P) var(program))(As tt(-p) var(program), except that
+var(program) does not accept a following tt(-)tt(-) to indicate the
+end of options.  In this case filenames must already be in a sane
+form for the program in question.)
 sitem(tt(-o) var(optstring))(The var(optstring) is split into words and
 passed down verbatim to the tt(cp), tt(ln) or tt(mv) command called to
 perform the work.  It should probably begin with a `tt(-)'.)
diff --git a/Functions/Misc/zmv b/Functions/Misc/zmv
index 4ba664e..269fe5b 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

pws


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: zmv with alternative commands
  2013-07-03 11:17 PATCH: zmv with alternative commands Peter Stephenson
@ 2013-07-03 15:57 ` Bart Schaefer
  2013-07-03 16:06   ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2013-07-03 15:57 UTC (permalink / raw)
  To: Zsh Hackers' List

On Jul 3, 12:17pm, Peter Stephenson wrote:
} Subject: PATCH: zmv with alternative commands
}
} I wanted to use zmv to "p4 integrate" (think alternatively of "git mv"
} --- not the same but should indicate what I'm using zmv for) some files.
} I encountered two problems: zmv doesn't split the words of the program
} you supply with -p, and also "p4 integrate" doesn't understand a
} following "--" to indicate the end of options for the subcommand.  I've
} introduced -P for the latter case.

Perhaps -P could itself take an argument which is the end-of-options
marker?  E.g. some older commands don't understand "--" but do accept
a single "-" all by itself.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: zmv with alternative commands
  2013-07-03 15:57 ` Bart Schaefer
@ 2013-07-03 16:06   ` Peter Stephenson
  2013-07-03 18:09     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2013-07-03 16:06 UTC (permalink / raw)
  To: Zsh Hackers' List

On Wed, 03 Jul 2013 08:57:19 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:

> On Jul 3, 12:17pm, Peter Stephenson wrote:
> } Subject: PATCH: zmv with alternative commands
> }
> } I wanted to use zmv to "p4 integrate" (think alternatively of "git mv"
> } --- not the same but should indicate what I'm using zmv for) some files.
> } I encountered two problems: zmv doesn't split the words of the program
> } you supply with -p, and also "p4 integrate" doesn't understand a
> } following "--" to indicate the end of options for the subcommand.  I've
> } introduced -P for the latter case.
> 
> Perhaps -P could itself take an argument which is the end-of-options
> marker?  E.g. some older commands don't understand "--" but do accept
> a single "-" all by itself.

That will already work since the end-of-option marker comes after the
program:

  zmv -P "cp --" foo bar

pws


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: zmv with alternative commands
  2013-07-03 16:06   ` Peter Stephenson
@ 2013-07-03 18:09     ` Bart Schaefer
  2013-07-03 19:00       ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2013-07-03 18:09 UTC (permalink / raw)
  To: Zsh Hackers' List

On Jul 3,  5:06pm, Peter Stephenson wrote:
} Subject: Re: PATCH: zmv with alternative commands
}
} > } I encountered two problems: zmv doesn't split the words of the program
} > } you supply with -p, and also "p4 integrate" doesn't understand a
} > } following "--" to indicate the end of options for the subcommand.  I've
} > } introduced -P for the latter case.
} > 
} > Perhaps -P could itself take an argument which is the end-of-options
} > marker?  E.g. some older commands don't understand "--" but do accept
} > a single "-" all by itself.
} 
} That will already work since the end-of-option marker comes after the
} program:
} 
}   zmv -P "cp --" foo bar

So if I were to do

    zmv -P -o"-b -d" "cp --" ...

??  No, I'd have to put the separator in the -o string.

Given that, what can you do with a word-splitting -p option

    zmv -p "cmd arg1 arg2" ...

that you can't do with

    zmv -o "arg1 arg2" cmd ...

instead?  If -p splits, do we even need -o any more, or is there a reason
that splitting with -o was separated from providing the command with -p?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: zmv with alternative commands
  2013-07-03 18:09     ` Bart Schaefer
@ 2013-07-03 19:00       ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2013-07-03 19:00 UTC (permalink / raw)
  To: Zsh Hackers' List

On Wed, 03 Jul 2013 11:09:33 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> If -p splits, do we even need -o any more, or is there a reason
> that splitting with -o was separated from providing the command with -p?

No, we don't really need -o any more.  It's more natural if you
don't need to change the command name, but want to add an option.  -p is
more natural if you are suppling consecutive words like a command and a
subcommand.  There's definitely no point in using both.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-07-03 19:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-03 11:17 PATCH: zmv with alternative commands Peter Stephenson
2013-07-03 15:57 ` Bart Schaefer
2013-07-03 16:06   ` Peter Stephenson
2013-07-03 18:09     ` Bart Schaefer
2013-07-03 19:00       ` Peter Stephenson

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