zsh-workers
 help / color / mirror / code / Atom feed
* Simpler for statements
@ 2007-12-08 17:08 Jörg Sommer
  2007-12-09  3:46 ` Mikael Magnusson
  0 siblings, 1 reply; 2+ messages in thread
From: Jörg Sommer @ 2007-12-08 17:08 UTC (permalink / raw)
  To: zsh-workers

Hi,

I look for a way to ease writing of for loops. I often have commands like
for i in other_files.*; do cmp file $i; done

On Dec 06, Stephane Chazelas posted a mail in the thread “avoid
interpretation of special characters” that gave me an idea:
accept-line()
{
    case "$BUFFER" in
      *"++"*)
        local repl
        repl=${${BUFFER#*++}%%++*}
        BUFFER="for i in $repl; do ${BUFFER/++$repl++/\$i}; done"
    esac
    zle .accept-line
}
zle -N accept-line

With this I can write “cmp file ++other_files.*++” and all is done. Or
“(cd ++*++; cvs up)” to update all cvs repositories.

Is there a better way to do this? Can I somehow improve my little
function?

Bye and thanks for the best shell on earth, Jörg.
-- 
Nicht was du bist, ist es was dich ehrt, wie du bist bestimmt den Wert.
Wünsche hat man oft und viel, nur wer lernt erreicht sein Ziel.


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

* Re: Simpler for statements
  2007-12-08 17:08 Simpler for statements Jörg Sommer
@ 2007-12-09  3:46 ` Mikael Magnusson
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Magnusson @ 2007-12-09  3:46 UTC (permalink / raw)
  To: zsh-workers

On 08/12/2007, Jörg Sommer <joerg@alea.gnuu.de> wrote:
> Hi,
>
> I look for a way to ease writing of for loops. I often have commands like
> for i in other_files.*; do cmp file $i; done
>
> Is there a better way to do this? Can I somehow improve my little
> function?

I like the
for a (other_files.*) {cmp file $a}
syntax, but I guess it depends on how easy it is to input {}() on your layout.
zsh will also allow
for a in other_files.*;cmp file $a
probably requires setopt shortloops, but a downside is you can't use ;
in the command.

-- 
Mikael Magnusson

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

end of thread, other threads:[~2007-12-09  3:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-08 17:08 Simpler for statements Jörg Sommer
2007-12-09  3:46 ` Mikael Magnusson

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