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

Re: Potential improvement for zmv



On Mar 27,  4:48pm, Wayne Davison wrote:
} Subject: Potential improvement for zmv
}
} I implemented a new option for zmv: -W.  This works just like -w, with
} the additional feature that it automatically transforms wildcards in the
} replacement pattern into a sequential series of ${1} .. ${N} vars.
} 
} Here's the patch.  Let me know what you think.

My only concern is that it should complain if the number of wildcards in
the destination is less than the number of wildcards in the source.  Else
you're likely to lose the rightmost patterns from the source, which are
probably the most important (the file name itself).

} Since I'm still a novice shell programmer, some of you wizards out
} there can undoubtedly improve the shell code I wrote.  For instance,
} I don't know if it's possible to increment $N inside a global search
} and replace (I resorted to using a loop).

You can just about do it:

integer N=0
x=(x x x x x x)
print ${(e)x//x/\$[++N]}

but the escaping to wrap each $[++N] in ${...} gets a bit arcane.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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