Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Tip of the day: previous command output
- X-seq: zsh-users 7887
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh-users List <zsh-users@xxxxxxxxxx>
- Subject: Re: Tip of the day: previous command output
- Date: Thu, 19 Aug 2004 10:16:10 -0700 (PDT)
- In-reply-to: <20040819164250.GA21575@xxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20040819085812.GL22962@localhost> <Pine.LNX.4.61.0408190748530.9464@xxxxxxxxxxxxxxxxxx> <20040819164250.GA21575@xxxxxxxxx>
- Reply-to: zsh-users@xxxxxxxxxx
On Thu, 19 Aug 2004, Andy Spiegl wrote:
> So I modified Barts "keep" to use
> kept=$($*)
Unless you also dropped the alias that prefixes keep with noglob, you
still need $~*, and to make it an array you probably want
kept=( $($~*) )
> So that I can do
> keep locate -i pictures | grep -i thursday | grep -i png
I don't know whether you intended this, but [with your original edit]
that's equivalent to
kept=$(locate -i pictures)
print -Rc - $kept | grep -i thursday | grep -i png
whereas I would guess that, rather, you meant
kept=( $(locate -i pictures | grep -i thursday | grep -i png) )
There's no provision -- except via a zmodload'd module -- for creating a
user-defined "precommand modifier" like (say) "time" or "coproc" that
syntatically consumes an entire pipeline. You'd have to use [inside
"keep"]
kept=( $(eval $*) )
[in this case NOT $~*] and write
keep locate -i pictures \| grep -i thursday \| grep -i png
An alternative is to write "keep" this way:
keep() {
kept=()
kept=( $~* )
if [[ ! -t 0 ]]; then
while read line; do
kept+=( $line )
done
fi
print -Rc - $kept
}
Then you can write
locate -i pictures | grep -i thursday | grep -i png | keep
and thanks to the magic of zsh running the last command of a pipe in the
current shell when that command is a function or builtin, you get what you
want in $kept.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author