zsh-workers
 help / color / mirror / code / Atom feed
* extra arguments inserted by glob thinger e:: get sorted afterwards
@ 2010-02-05 15:15 Mikael Magnusson
  2010-02-05 15:49 ` Peter Stephenson
  2010-02-08 10:08 ` Jörg Sommer
  0 siblings, 2 replies; 8+ messages in thread
From: Mikael Magnusson @ 2010-02-05 15:15 UTC (permalink / raw)
  To: zsh workers

Hi, someone just asked on irc how to give a globbed list of files to a
program with a -f inserted before each argument, so I told him
*(e:'reply=(-f $REPLY)':), that doesn't work however, as the arguments
are resorted afterwards, which seems like the less useful way to do
it. Of course one can add oN, but it would be nicer if you could both
sort files and add extra arguments. Stuff like oa doesn't make sense
on the inserted arguments anyway.

% print -- *.sh(oNe:'reply=(-f $REPLY)':)
-f zmpc.sh -f ifs.sh -f test.sh -f script_pandora.sh
% print -- *.sh(e:'reply=(-f $REPLY)':)
-f -f -f -f ifs.sh script_pandora.sh test.sh zmpc.sh

-- 
Mikael Magnusson


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

* Re: extra arguments inserted by glob thinger e:: get sorted afterwards
  2010-02-05 15:15 extra arguments inserted by glob thinger e:: get sorted afterwards Mikael Magnusson
@ 2010-02-05 15:49 ` Peter Stephenson
  2010-02-05 16:50   ` Bart Schaefer
  2010-02-08 10:08 ` Jörg Sommer
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2010-02-05 15:49 UTC (permalink / raw)
  To: zsh workers

Mikael Magnusson wrote:
> Hi, someone just asked on irc how to give a globbed list of files to a
> program with a -f inserted before each argument, so I told him
> *(e:'reply=(-f $REPLY)':), that doesn't work however, as the arguments
> are resorted afterwards, which seems like the less useful way to do
> it.

It's the *only* way to do it.  The arguments are all assumed to be
files, which is after all the point of globbing.  Either you get them
sorted as files or you don't get them sorted.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

* Re: extra arguments inserted by glob thinger e:: get sorted afterwards
  2010-02-05 15:49 ` Peter Stephenson
@ 2010-02-05 16:50   ` Bart Schaefer
  0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2010-02-05 16:50 UTC (permalink / raw)
  To: zsh workers

On Feb 5,  3:49pm, Peter Stephenson wrote:
}
} Mikael Magnusson wrote:
} > Hi, someone just asked on irc how to give a globbed list of files to a
} > program with a -f inserted before each argument, so I told him
} > *(e:'reply=(-f $REPLY)':), that doesn't work however, as the arguments
} > are resorted afterwards, which seems like the less useful way to do
} > it.
} 
} It's the *only* way to do it.  The arguments are all assumed to be
} files, which is after all the point of globbing.  Either you get them
} sorted as files or you don't get them sorted.

I suppose what Mikael would like is for "-f $REPLY" to be glob-sorted
as a unit, but still word-split at parse time.  Breaks if the actual
file name has spaces.

The manual sort of implies that *(e.'reply+="-f $REPLY"'.:x) should be
the way to do this -- glob first, then split the result into words at
whitespace after; the doc says only that :x doesn't work for parameters,
failing to mention that it doesn't work for globbing either.  However,
there's an equally good argument that the :x would apply before sorting,
if it worked at all.


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

* Re: extra arguments inserted by glob thinger e:: get sorted afterwards
  2010-02-05 15:15 extra arguments inserted by glob thinger e:: get sorted afterwards Mikael Magnusson
  2010-02-05 15:49 ` Peter Stephenson
@ 2010-02-08 10:08 ` Jörg Sommer
  2010-02-08 12:44   ` Frank Terbeck
  1 sibling, 1 reply; 8+ messages in thread
From: Jörg Sommer @ 2010-02-08 10:08 UTC (permalink / raw)
  To: zsh-workers

Hello Mikael,

Mikael Magnusson <mikachu@gmail.com> wrote:
> Hi, someone just asked on irc how to give a globbed list of files to a
> program with a -f inserted before each argument, so I told him
> *(e:'reply=(-f $REPLY)':), that doesn't work however, as the arguments
> are resorted afterwards, which seems like the less useful way to do
> it. Of course one can add oN, but it would be nicer if you could both
> sort files and add extra arguments. Stuff like oa doesn't make sense
> on the inserted arguments anyway.
>
> % print -- *.sh(oNe:'reply=(-f $REPLY)':)
> -f zmpc.sh -f ifs.sh -f test.sh -f script_pandora.sh

Why not use $^?

% print -- -f\ ${(f)^"$(print -l /bin/ls*)"}
-f /bin/ls -f /bin/lsmod

Bye, Jörg.
-- 
> Definiere ‚Demokratie‘ …
… eine Mehrheit beweist einer Minderheit, dass Widerstand zwecklos ist.


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

* Re: extra arguments inserted by glob thinger e:: get sorted afterwards
  2010-02-08 10:08 ` Jörg Sommer
@ 2010-02-08 12:44   ` Frank Terbeck
  2010-02-08 17:16     ` Mikael Magnusson
  0 siblings, 1 reply; 8+ messages in thread
From: Frank Terbeck @ 2010-02-08 12:44 UTC (permalink / raw)
  To: Jörg Sommer; +Cc: zsh-workers

Jörg Sommer wrote:
[...]
>> % print -- *.sh(oNe:'reply=(-f $REPLY)':)
>> -f zmpc.sh -f ifs.sh -f test.sh -f script_pandora.sh
>
> Why not use $^?
>
> % print -- -f\ ${(f)^"$(print -l /bin/ls*)"}
> -f /bin/ls -f /bin/lsmod

Because:
% print -l -- -f\ ${(f)^"$(print -l /bin/ls*)"}
-f /bin/ls
-f /bin/lsmod

"-f /bin/ls" would be one word to the shell.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


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

* Re: extra arguments inserted by glob thinger e:: get sorted  afterwards
  2010-02-08 12:44   ` Frank Terbeck
@ 2010-02-08 17:16     ` Mikael Magnusson
  2010-02-08 17:42       ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Mikael Magnusson @ 2010-02-08 17:16 UTC (permalink / raw)
  To: Frank Terbeck; +Cc: Jörg Sommer, zsh-workers

On 8 February 2010 13:44, Frank Terbeck <ft@bewatermyfriend.org> wrote:
> Jörg Sommer wrote:
> [...]
>>> % print -- *.sh(oNe:'reply=(-f $REPLY)':)
>>> -f zmpc.sh -f ifs.sh -f test.sh -f script_pandora.sh
>>
>> Why not use $^?
>>
>> % print -- -f\ ${(f)^"$(print -l /bin/ls*)"}
>> -f /bin/ls -f /bin/lsmod
>
> Because:
> % print -l -- -f\ ${(f)^"$(print -l /bin/ls*)"}
> -f /bin/ls
> -f /bin/lsmod
>
> "-f /bin/ls" would be one word to the shell.

And also because:
# touch /bin/ls'
fail'
% print -- -f\ ${(f)^"$(print -l /bin/ls*)"}
-f /bin/ls
-f /bin/ls
-f fail
-f /bin/lsmod

$() is almost impossible to get right wrt quoting.
print -l -- -f\ ${(0)^"$(printf '%s\0' /bin/ls*)"} probably works a
bit better, but of course it's still useless since the -f is not a
separate parameter.

As an aside, is "$(echo a b c)" the only way to get an 'inline' array
in a ${} expression? I sometimes want to use a glob qualifier on a
middle part of a path but then I need to use temp arrays (and I'd
rather not use $() there).

-- 
Mikael Magnusson


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

* Re: extra arguments inserted by glob thinger e:: get sorted afterwards
  2010-02-08 17:16     ` Mikael Magnusson
@ 2010-02-08 17:42       ` Bart Schaefer
  2010-02-08 18:01         ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2010-02-08 17:42 UTC (permalink / raw)
  To: zsh-workers

On Feb 8,  6:16pm, Mikael Magnusson wrote:
}
} As an aside, is "$(echo a b c)" the only way to get an 'inline' array
} in a ${} expression?

The most obvious is ${=:-one two three} which applies word splitting
to the string to the right of the hyphen.  Interestingly this even
works with quoting, where I had assumed it would break within words:

zsh% print -l ${=:-"one two" three\ four 'five six'}
one two
three four
five six

And you can combine it with rcexpandparam:

zsh% print -l X${^=:-"one two" three\ four 'five six'}Z
Xone twoZ
Xthree fourZ
Xfive sixZ


-- 


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

* Re: extra arguments inserted by glob thinger e:: get sorted afterwards
  2010-02-08 17:42       ` Bart Schaefer
@ 2010-02-08 18:01         ` Peter Stephenson
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2010-02-08 18:01 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:
> The most obvious is ${=:-one two three} which applies word splitting
> to the string to the right of the hyphen.  Interestingly this even
> works with quoting, where I had assumed it would break within words:

This was part of the set of changes Wayne made to parameter substitution
for quoting which I see is already four years old, Src/subst.c revisions
1.45 to 1.49.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

end of thread, other threads:[~2010-02-08 18:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-05 15:15 extra arguments inserted by glob thinger e:: get sorted afterwards Mikael Magnusson
2010-02-05 15:49 ` Peter Stephenson
2010-02-05 16:50   ` Bart Schaefer
2010-02-08 10:08 ` Jörg Sommer
2010-02-08 12:44   ` Frank Terbeck
2010-02-08 17:16     ` Mikael Magnusson
2010-02-08 17:42       ` Bart Schaefer
2010-02-08 18:01         ` 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).