From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10184 invoked from network); 19 Aug 2004 15:23:10 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 19 Aug 2004 15:23:10 -0000 Received: (qmail 94628 invoked from network); 19 Aug 2004 15:23:04 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 19 Aug 2004 15:23:04 -0000 Received: (qmail 8387 invoked by alias); 19 Aug 2004 15:22:20 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7885 Received: (qmail 8377 invoked from network); 19 Aug 2004 15:22:20 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by 130.225.247.90 with SMTP; 19 Aug 2004 15:22:20 -0000 Received: (qmail 92867 invoked from network); 19 Aug 2004 15:20:21 -0000 Received: from unknown (HELO moonbase.zanshin.com) (167.160.213.139) by a.mx.sunsite.dk with SMTP; 19 Aug 2004 15:20:19 -0000 Received: from toltec.zanshin.com (toltec.zanshin.com [64.84.47.166]) by moonbase.zanshin.com (8.12.11/8.12.11) with ESMTP id i7JFKIbG005495 for ; Thu, 19 Aug 2004 08:20:18 -0700 Date: Thu, 19 Aug 2004 08:20:17 -0700 (PDT) From: Bart Schaefer Reply-To: zsh-users@sunsite.dk To: Zsh-users List Subject: Re: Tip of the day: previous command output In-Reply-To: <20040819085812.GL22962@localhost> Message-ID: References: <20040819085812.GL22962@localhost> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=-0.0 required=6.0 tests=BAYES_44 autolearn=no version=2.63 X-Spam-Hits: -0.0 On Thu, 19 Aug 2004, Jesper Holmberg wrote: > The motivation for the following snippet is the fact that I often do a > 'find' or a 'locate' to find some files I'm interested in, and then want > to do some action on one of the files I just found. [...] > What this does is that it repeats the previous command, saving the output > in a string. I use this little function [*] for a similar purpose: keep () { kept=() # Erase old value in case of error on next line kept=($~*) print -Rc - $kept } alias keep='noglob keep ' Note that "kept" is deliberately not declared local. E.g. I might do patch < zsh-workers_NNNN.diff keep **/*.(orig|rej) emacs ${${kept:#*.orig}:r} rm $kept That way I don't have to redo the possibly-expensive recursive glob twice; the result is all stashed in $kept where I can manipulate the file names and pick out the ones I want to work on. I haven't bothered to combine it with a completion key because I hardly ever want one specific file or its unmodified name; I almost always end up typing some kind of parameter substitution expression. [*] OK, I'm fibbing. I actually call it "show" but there's an MH command by that name that zsh may try to do completion for, so I changed the name for public consumption.