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

Re: Problems with zargs (Was: xargs should be a builtin)



On Wed, 11 Apr 2012 11:06:42 +0100
Stephane Chazelas <stephane.chazelas@xxxxxxxxx> wrote:
> By the way, there seems to be some issues with zargs:
> 
> ~$ zargs a b '' -- print -rl
> a
> b
> ~$ zargs a -- print -rl ''
> a
> ~$ zargs -e a '' print -rl
> a print -rl
> ~$ zargs --eof= a '' print -rl
> a

It helps if everyone always says explicitly what the problem actually
is, it saves lots of guesswork.

I've come up with the following for the problems I understand, but I'm
sure it could do with a bit more prodding.

Index: Functions/Misc/zargs
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Misc/zargs,v
retrieving revision 1.6
diff -p -u -r1.6 zargs
--- Functions/Misc/zargs	14 Aug 2011 13:40:53 -0000	1.6
+++ Functions/Misc/zargs	11 Apr 2012 16:14:48 -0000
@@ -167,11 +167,11 @@ if [[ $eof == -(e|-eof) ]]; then ((end=A
 elif (( $#eof )); then end=$argv[(i)${eof##-(e|-eof=)}]
 else end=$argv[(i)--]
 fi
-local -a args call command; command=( ${argv[end+1,-1]} )
+local -a args call command; command=( "${(@)argv[end+1,-1]}" )
 
 if (( $opts[(I)-(null|0)] ))
-then set -- ${(ps:\000:)argv[1,end-1]}
-else set -- $argv[1,end-1]
+then set -- "${(@ps:\000:)argv[1,end-1]}"
+else set -- "${(@)argv[1,end-1]}"
 fi
 
 if [[ -n $command ]]
@@ -187,7 +187,7 @@ local execute='
     then print -u2 -r -- "$call"
     fi
     eval "{
-	\$call
+	\"\${(@)call}\"
     } $bg"'
 local ret=0 analyze='
     case $? in
@@ -275,11 +275,11 @@ do
 	((ARGC)) || break
 	for (( end=l; end && ${(c)#argv[1,end]} > s; end/=2 )) { }
 	(( end > n && ( end = n ) ))
-	args=( $argv[1,end] )
+	args=( "${(@)argv[1,end]}" )
 	shift $((end > ARGC ? ARGC : end))
 	if (( $#i ))
-	then call=( ${command/$i/$args} )
-	else call=( $command $args )
+	then call=( "${(@)command/$i/$args}" )
+	else call=( "${(@)command}" "${(@)args}" )
 	fi
 	if (( ${(c)#call} > s ))
 	then

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



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