zsh-users
 help / color / mirror / code / Atom feed
* transformations of glob results
@ 2015-09-23  8:06 Marc Chantreux
  2015-09-23 13:49 ` Mikael Magnusson
  2015-09-23 14:58 ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Marc Chantreux @ 2015-09-23  8:06 UTC (permalink / raw)
  To: zsh-users

hello people,

i wrote a glob result transformation that way:

    l=( /etc/sympa/*/robot.conf(:h:t) )
    l=( listmaster@$^l )
    print ${(j:,:)l}

but i really would like to know if there is a simple, readable way to
write it in one expression. the perl counterpart would be

    join ','
    , map 'listmaster@'.(split "/")[-2]
    , glob "/etc/*/robot.conf"

and i tried variations around

    print ${(j:,:)${(@)listmaster@${(^) /etc/sympa/*/robot.conf(:h:t) }}}

which

    * doesn't work
    * actually looks ugly

any help from a zsh poweruser ?

regards

-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln


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

* Re: transformations of glob results
  2015-09-23  8:06 transformations of glob results Marc Chantreux
@ 2015-09-23 13:49 ` Mikael Magnusson
  2015-09-23 14:41   ` Marc Chantreux
  2015-09-23 14:58 ` Bart Schaefer
  1 sibling, 1 reply; 5+ messages in thread
From: Mikael Magnusson @ 2015-09-23 13:49 UTC (permalink / raw)
  To: Marc Chantreux; +Cc: Zsh Users

On Wed, Sep 23, 2015 at 10:06 AM, Marc Chantreux <khatar@phear.org> wrote:
> hello people,
>
> i wrote a glob result transformation that way:
>
>     l=( /etc/sympa/*/robot.conf(:h:t) )
>     l=( listmaster@$^l )
>     print ${(j:,:)l}
>
> but i really would like to know if there is a simple, readable way to
> write it in one expression.

Not really, parameter expansion takes place before globbing so you
need to do the * separately before the other stuff. You can cheat and
do things with e:: but that is much slower in this case (and
technically the thing inside the :: is a separate expression too), or
use an anonymous function but all that really does is give you a free
local variable, (eg, () { print ${(j:,:):-listmaster@$^@}} }
/etc/sympa/*/robot.conf(:h:t) (not tested, may have typos) )

-- 
Mikael Magnusson


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

* Re: transformations of glob results
  2015-09-23 13:49 ` Mikael Magnusson
@ 2015-09-23 14:41   ` Marc Chantreux
  2015-09-23 20:59     ` Mikael Magnusson
  0 siblings, 1 reply; 5+ messages in thread
From: Marc Chantreux @ 2015-09-23 14:41 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Zsh Users

hello, 

> use an anonymous function but all that really does is give you a free
> local variable, (eg, () { print ${(j:,:):-listmaster@$^@}} }  

the thing is: you can't expand a list in an anymous function as it
communicates with pipes. i'm stuck there but the question was out of
curiosity.

thanks a lot for answering.


marc 


-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln


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

* Re: transformations of glob results
  2015-09-23  8:06 transformations of glob results Marc Chantreux
  2015-09-23 13:49 ` Mikael Magnusson
@ 2015-09-23 14:58 ` Bart Schaefer
  1 sibling, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2015-09-23 14:58 UTC (permalink / raw)
  To: zsh-users

On Sep 23, 10:06am, Marc Chantreux wrote:
}
} and i tried variations around
} 
}     print ${(j:,:)${(@)listmaster@${(^) /etc/sympa/*/robot.conf(:h:t) }}}
} 
} which
} 
}     * doesn't work
}     * actually looks ugly
} 
} any help from a zsh poweruser ?

As Mikael said, this is difficult because globbing comes last.  You
can fork off the glob $( print -NR /etc/sympa/*/robot.conf(:h:t) )
and then split and rejoin that, but it'll be slower.


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

* Re: transformations of glob results
  2015-09-23 14:41   ` Marc Chantreux
@ 2015-09-23 20:59     ` Mikael Magnusson
  0 siblings, 0 replies; 5+ messages in thread
From: Mikael Magnusson @ 2015-09-23 20:59 UTC (permalink / raw)
  To: Marc Chantreux; +Cc: Zsh Users

On Wed, Sep 23, 2015 at 4:41 PM, Marc Chantreux <khatar@phear.org> wrote:
> hello,
>
>> use an anonymous function but all that really does is give you a free
>> local variable, (eg, () { print ${(j:,:):-listmaster@$^@}} }
>
> the thing is: you can't expand a list in an anymous function as it
> communicates with pipes. i'm stuck there but the question was out of
> curiosity.

I'm not sure what you mean by this. There are no pipes in any of the
commands you or I wrote.

% () { print ${(j:,:):-listmaster@$^@} } /etc/*/.keep(:h:t)
listmaster@conf.d,listmaster@env.d,listmaster@modprobe.d,listmaster@opt,listmaster@xml

(as it happens, I did have a } too many before).

-- 
Mikael Magnusson


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

end of thread, other threads:[~2015-09-23 20:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-23  8:06 transformations of glob results Marc Chantreux
2015-09-23 13:49 ` Mikael Magnusson
2015-09-23 14:41   ` Marc Chantreux
2015-09-23 20:59     ` Mikael Magnusson
2015-09-23 14:58 ` Bart Schaefer

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