From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20775 invoked from network); 19 Aug 2004 09:00:43 -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 09:00:43 -0000 Received: (qmail 54319 invoked from network); 19 Aug 2004 09:00:35 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 19 Aug 2004 09:00:35 -0000 Received: (qmail 29608 invoked by alias); 19 Aug 2004 08:59:48 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7884 Received: (qmail 29599 invoked from network); 19 Aug 2004 08:59:48 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by 130.225.247.90 with SMTP; 19 Aug 2004 08:59:48 -0000 Received: (qmail 52283 invoked from network); 19 Aug 2004 08:58:44 -0000 Received: from smtp1.su.se (130.237.162.112) by a.mx.sunsite.dk with SMTP; 19 Aug 2004 08:58:41 -0000 Received: from localhost (smtp1.su.se [127.0.0.1]) by smtp1.su.se (Postfix) with ESMTP id E214A386F0 for ; Thu, 19 Aug 2004 10:58:40 +0200 (CEST) Received: from smtp1.su.se ([127.0.0.1]) by localhost (smtp1.su.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 24267-01-65 for ; Thu, 19 Aug 2004 10:58:40 +0200 (CEST) Received: from unni.dsv.su.se (unni.dsv.su.se [130.237.161.27]) by smtp1.su.se (Postfix) with ESMTP id C2E48380A9 for ; Thu, 19 Aug 2004 10:58:28 +0200 (CEST) Received: from localhost (dhcp-161-153.dsv.su.se [130.237.161.153]) by unni.dsv.su.se (Postfix) with ESMTP id 9E0B58B310 for ; Thu, 19 Aug 2004 10:58:28 +0200 (CEST) Received: from jesper by localhost with local (Exim 4.34) id 1BxikO-0004gF-V9 for zsh-users@sunsite.dk; Thu, 19 Aug 2004 10:58:12 +0200 Date: Thu, 19 Aug 2004 10:58:12 +0200 From: Jesper Holmberg To: Zsh-users List Subject: Tip of the day: previous command output Message-ID: <20040819085812.GL22962@localhost> Mail-Followup-To: Zsh-users List Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.6+20040722i Sender: Jesper Holmberg X-Virus-Scanned: by amavisd-new at su.se X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.1 required=6.0 tests=BAYES_30,FROM_ENDS_IN_NUMS autolearn=no version=2.63 X-Spam-Hits: 0.1 Someone asked for zsh tips a couple of weeks ago. Here's something I use a lot. I got the basic idea from some user group somewhere, and then I've tweaked the idea to suit my needs. 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. This function provides a way to put completions from the output of the previous command on the command line. _jh-prev-result () { hstring=$(eval `fc -l -n -1`) set -A hlist ${(@s/ /)hstring} compadd - ${hlist} } zle -C jh-prev-comp menu-complete _jh-prev-result bindkey '\ee' jh-prev-comp What this does is that it repeats the previous command, saving the output in a string. It then splits the output string on new-lines, and quotes each element (so that for example file names containing spaces get properly quoted). I then bind the function to a menu-complete-like widget, so that I can step through the alternatives. Test it together with 'loocate' or 'find'. Perhaps someone finds this useful, and any suggestions for improvement would be appreciated. Jesper