zsh-users
 help / color / mirror / code / Atom feed
* globbing with interposition
@ 2005-04-19  7:21 Eric Smith
  2005-04-19  7:50 ` DervishD
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Eric Smith @ 2005-04-19  7:21 UTC (permalink / raw)
  To: Zsh Users

Hi

I want to be able in a simple command to glob all files
but there needs to be a `-a' in front of each globbed file name.

So, I would like to do something like this (which obviously
dont work) in order to achieve the above.

mutt eric -a fotos* -s "all images attached" </dev/null

thanks

-- 
Eric Smith


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

* Re: globbing with interposition
  2005-04-19  7:21 globbing with interposition Eric Smith
@ 2005-04-19  7:50 ` DervishD
  2005-04-19  8:22 ` J
  2005-04-19 18:36 ` Oliver Kiddle
  2 siblings, 0 replies; 11+ messages in thread
From: DervishD @ 2005-04-19  7:50 UTC (permalink / raw)
  To: Eric Smith; +Cc: Zsh Users

    Hi Eric :)

 * Eric Smith <es@fruitcom.com> dixit:
> So, I would like to do something like this (which obviously
> dont work) in order to achieve the above.
> 
> mutt eric -a fotos* -s "all images attached" </dev/null

    Quick'n'dirty hack (obviously must exist a better solution):

    mutt eric `for file in * ; print -- -a $file' -s ...

    The main problem is that this doesn't work with files that has
spaces in the name. If mutt doesn't need a space between '-a' and the
file name for the attach, you can do this:

    mutt eric "`for file in * ; print -- -a $file'" -s ...

    This quotes the space between the '-a' and the filename. I don't
know of any other solution that you can use in the command line. If
you need selective quoting you can 'build' the command line:

    commandline=(mutt eric)
    for file in *
    do
        commandline+=(-a "$file")
    done
    commandline+=(-s "all...")
    
    After that, you run this:
    $ $commandline </dev/null

    Hope that helps :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...


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

* Re: globbing with interposition
  2005-04-19  7:21 globbing with interposition Eric Smith
  2005-04-19  7:50 ` DervishD
@ 2005-04-19  8:22 ` J
  2005-04-19  8:35   ` DervishD
  2005-04-19 15:25   ` Bart Schaefer
  2005-04-19 18:36 ` Oliver Kiddle
  2 siblings, 2 replies; 11+ messages in thread
From: J @ 2005-04-19  8:22 UTC (permalink / raw)
  To: Eric Smith; +Cc: Zsh Users

> I want to be able in a simple command to glob all files
> but there needs to be a `-a' in front of each globbed file name.
> 
> mutt eric -a fotos* -s "all images attached" </dev/null

I would suggest something like

a=(fotos*) mutt eric '-a '${^a} -s "all images attached" </dev/null
or
mutt eric '-a '${^$(print *)} -s "all images attached" </dev/null

This creates a temporary array containing all file names in the
globbing pattern and expands it with the RC_EXPAND_PARAM option set.

-- 
J
"If you wish to leave a record of your call,
 please state your messij at the sound of the tone."


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

* Re: globbing with interposition
  2005-04-19  8:22 ` J
@ 2005-04-19  8:35   ` DervishD
  2005-04-19 15:25   ` Bart Schaefer
  1 sibling, 0 replies; 11+ messages in thread
From: DervishD @ 2005-04-19  8:35 UTC (permalink / raw)
  To: J; +Cc: Eric Smith, Zsh Users

    Hi Jean :)

 * J <jean.chalard@gmail.com> dixit:
> > I want to be able in a simple command to glob all files
> > but there needs to be a `-a' in front of each globbed file name.
> > 
> > mutt eric -a fotos* -s "all images attached" </dev/null
> I would suggest something like
> 
> a=(fotos*) mutt eric '-a '${^a} -s "all images attached" </dev/null
> or
> mutt eric '-a '${^$(print *)} -s "all images attached" </dev/null

    Nice!! I forgot the RC_EXPAND_PARAM option and the caret
notation. This is shorter and does appropriate quoting.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...


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

* Re: globbing with interposition
  2005-04-19  8:22 ` J
  2005-04-19  8:35   ` DervishD
@ 2005-04-19 15:25   ` Bart Schaefer
  2005-04-19 15:36     ` J
                       ` (2 more replies)
  1 sibling, 3 replies; 11+ messages in thread
From: Bart Schaefer @ 2005-04-19 15:25 UTC (permalink / raw)
  To: Zsh Users

On Apr 19,  9:21am, Eric Smith wrote:
}
} mutt eric -a fotos* -s "all images attached" </dev/null

It would be really nice if this worked:

    mutt eric fotos*(e:'reply=(-a $REPLY)':) -s "all images attached"

However, there's no way tell zsh NOT to sort the results of globbing.
I mention this so that I can propose a new key for the 'o' and 'O' glob
qualifiers, a key meaning "don't sort this glob at all."

For bizarre reasons I don't immediately understand, the following does
what you want, but probably isn't guaranteed to keep working in future
releases:

    mutt eric fotos*(e:'reply=($REPLY -a)':od) -s "all images attached"

(and no, using Od instead of od doesn't change anything).  That is, the
'od' qualifier prevents zsh from sorting the full list, but for some
reason zsh reverses the $reply array; e.g.:

    touch frobnitz flobozz
    print f*z(e:'reply=(1 2 $REPLY 3 4)':od)

will output something like

    4 3 flobozz 2 1 4 3 frobnitz 2 1

This happens for 'oa', 'oc', and 'om' as well.

On Apr 19, 10:22am, J wrote:
} Subject: Re: globbing with interposition
}
} a=(fotos*) mutt eric '-a '${^a} -s "all images attached" </dev/null

That doesn't work because the order of assignment and expansion is not
what you expect.  That is, the ${^a} is expanded at parse time, but
the assignment prefixes are handled at execute time.  You'd have to do

a=(fotos*) eval 'mutt eric "-a "${^a} -s "all images attached" </dev/null'

but that suffers from the same problems as this:

} mutt eric '-a '${^$(print *)} -s "all images attached" </dev/null

That one fails if there are spaces in any of the file names, and on
top of that the space character after the -a is quoted, so mutt will
see '-a somefile' all as one string, not as '-a' and 'somefile'.

The only sure-fire way I can see to do it (without a loop similar to
Raúl's first suggestion) is like this:

    a=()
    : fotos*(e:'a+=(-a $REPLY)':)
    mutt eric $a -s "all images attached" </dev/null


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

* Re: globbing with interposition
  2005-04-19 15:25   ` Bart Schaefer
@ 2005-04-19 15:36     ` J
  2005-04-19 15:59     ` Peter Stephenson
  2005-04-19 16:46     ` DervishD
  2 siblings, 0 replies; 11+ messages in thread
From: J @ 2005-04-19 15:36 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

> On Apr 19, 10:22am, J wrote:
> } Subject: Re: globbing with interposition
> }
> } a=(fotos*) mutt eric '-a '${^a} -s "all images attached" </dev/null
> 
> That doesn't work because the order of assignment and expansion is not
> what you expect.  That is, the ${^a} is expanded at parse time, but
> the assignment prefixes are handled at execute time.  You'd have to do

Oh. I was bitten by the fact I tested it after I already give the
value to the array and assumed the variable was reassigned on this
line before evaluation. My bad.
Anyway, I should have been aware of the problems with the spaces in
filenames and the quoted space anyway.

Well, sorry for the noise.

-- 
J
"If you wish to leave a record of your call,
 please state your messij at the sound of the tone."


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

* Re: globbing with interposition
  2005-04-19 15:25   ` Bart Schaefer
  2005-04-19 15:36     ` J
@ 2005-04-19 15:59     ` Peter Stephenson
  2005-04-19 16:22       ` Bart Schaefer
  2005-04-19 16:46     ` DervishD
  2 siblings, 1 reply; 11+ messages in thread
From: Peter Stephenson @ 2005-04-19 15:59 UTC (permalink / raw)
  To: Zsh Users

Bart Schaefer wrote:
> For bizarre reasons I don't immediately understand, the following does
> what you want, but probably isn't guaranteed to keep working in future
> releases:
> 
>     mutt eric fotos*(e:'reply=($REPLY -a)':od) -s "all images attached"

od doesn't sort at all, which is sort of implied by:

    if d, files in subdirectories appear before  those
    in the current directory at each level of the search --- this is
    best combined with other criteria, for example `odon' to sort on
    names  for files within the same directory

The effect of "not sorting at all" is likely to be that the files are
read in inode order, except it's not documented how they are likely to
be inserted into the final list.  It does seem that they're reversed on
Linux:

  % touch a b c d
  % print *(od)
  d c b a
  % rm b
  % touch e
  % print *(od)
  d c e a

The reversal is not an effect of the (od) itself, which simply returns a
the difference of the number of slashes in the file, i.e. zero.  It
looks like it's a side effect of qsort when two files compare equal.
The qsort documentation says:

    The relative order in the output of two items  that  compare
    as equal is unpredictable.

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


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************


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

* Re: globbing with interposition
  2005-04-19 15:59     ` Peter Stephenson
@ 2005-04-19 16:22       ` Bart Schaefer
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2005-04-19 16:22 UTC (permalink / raw)
  To: Zsh Users

On Apr 19,  4:59pm, Peter Stephenson wrote:
} Subject: Re: globbing with interposition
}
} The effect of "not sorting at all" is likely to be that the files are
} read in inode order, except it's not documented how they are likely to
} be inserted into the final list.  It does seem that they're reversed on
} Linux:

You're missing the point, which is that in reply=(1 2 $REPLY 3 4) there
are no files named 1 2 3 4, yet zsh reverses the array anyway.  It can't
be doing so based on inode order becase there are no inodes.

Also od and Od don't matter -- the array is reversed in either case -- so
it's not an effect of the 'o' flag.


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

* Re: globbing with interposition
  2005-04-19 15:25   ` Bart Schaefer
  2005-04-19 15:36     ` J
  2005-04-19 15:59     ` Peter Stephenson
@ 2005-04-19 16:46     ` DervishD
  2 siblings, 0 replies; 11+ messages in thread
From: DervishD @ 2005-04-19 16:46 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> } a=(fotos*) mutt eric '-a '${^a} -s "all images attached" </dev/null
> That doesn't work because the order of assignment and expansion is not
> what you expect.  That is, the ${^a} is expanded at parse time, but
> the assignment prefixes are handled at execute time.

    Oops, I did the assignment on one command line and the 'mutt'
command line in another. Well, in fact I had the array already filled
and I just used it. So I didn't catch the problem :(

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...


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

* Re: globbing with interposition
  2005-04-19  7:21 globbing with interposition Eric Smith
  2005-04-19  7:50 ` DervishD
  2005-04-19  8:22 ` J
@ 2005-04-19 18:36 ` Oliver Kiddle
  2005-04-21 10:45   ` globbing with interposition -> rocking Eric Smith - Fruitcom
  2 siblings, 1 reply; 11+ messages in thread
From: Oliver Kiddle @ 2005-04-19 18:36 UTC (permalink / raw)
  To: Eric Smith; +Cc: Zsh Users

Eric Smith wrote:
> I want to be able in a simple command to glob all files
> but there needs to be a `-a' in front of each globbed file name.
> 
> So, I would like to do something like this (which obviously
> dont work) in order to achieve the above.
> 
> mutt eric -a fotos* -s "all images attached" </dev/null
> 

The following works:

  files=( fotos* )
  mutt eric {-a,$^files} -s "all images attached" </dev/null

That may seem strange but I suppose the array must be expanded before
the braces.

Oliver


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

* Re: globbing with interposition -> rocking
  2005-04-19 18:36 ` Oliver Kiddle
@ 2005-04-21 10:45   ` Eric Smith - Fruitcom
  0 siblings, 0 replies; 11+ messages in thread
From: Eric Smith - Fruitcom @ 2005-04-21 10:45 UTC (permalink / raw)
  To: Zsh Users

According to Oliver Kiddle on Tue, Apr 19, 2005 at 08:36:28PM +0200:
}   
}   The following works:
}   
}     files=( fotos* )
}     mutt eric {-a,$^files} -s "all images attached" </dev/null
}   

This works too and is so cool - thanks Oliver

f=(I/clems/*JPG I/oranges/*); mutt eric {-a,$^f} -s "Clementine and Orange Photos" </dev/null



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

end of thread, other threads:[~2005-04-21 10:46 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-19  7:21 globbing with interposition Eric Smith
2005-04-19  7:50 ` DervishD
2005-04-19  8:22 ` J
2005-04-19  8:35   ` DervishD
2005-04-19 15:25   ` Bart Schaefer
2005-04-19 15:36     ` J
2005-04-19 15:59     ` Peter Stephenson
2005-04-19 16:22       ` Bart Schaefer
2005-04-19 16:46     ` DervishD
2005-04-19 18:36 ` Oliver Kiddle
2005-04-21 10:45   ` globbing with interposition -> rocking Eric Smith - Fruitcom

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