From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14113 invoked from network); 21 Aug 2004 04:28:38 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 21 Aug 2004 04:28:38 -0000 Received: (qmail 16130 invoked from network); 21 Aug 2004 04:28:32 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Aug 2004 04:28:32 -0000 Received: (qmail 18510 invoked by alias); 21 Aug 2004 04:27:48 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7898 Received: (qmail 18500 invoked from network); 21 Aug 2004 04:27:48 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by 130.225.247.90 with SMTP; 21 Aug 2004 04:27:48 -0000 Received: (qmail 14690 invoked from network); 21 Aug 2004 04:25:50 -0000 Received: from unknown (HELO moonbase.zanshin.com) (167.160.213.139) by a.mx.sunsite.dk with SMTP; 21 Aug 2004 04:25:48 -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 i7L4PliW014781 for ; Fri, 20 Aug 2004 21:25:47 -0700 Date: Fri, 20 Aug 2004 21:25:47 -0700 (PDT) From: Bart Schaefer Reply-To: zsh-users@sunsite.dk To: zsh-users@sunsite.dk Subject: Re: Tip of the day: previous command output In-Reply-To: <20040820145032.GH13530@ay.vinc17.org> Message-ID: References: <20040819085812.GL22962@localhost> <20040819164250.GA21575@spiegl.de> <20040820121202.GA31466@spiegl.de> <20040820145032.GH13530@ay.vinc17.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Content-ID: 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_40 autolearn=no version=2.63 X-Spam-Hits: -0.0 On Fri, 20 Aug 2004, Andy Spiegl wrote: > What would be the difference if I dropped alias with the noglob and used > $* instead of $~*? I guess zsh would expand the globs before calling > the function, right? Right. > But the result should be the same or not? Should be the same. Waiting to expand uses a little less memory. On Fri, 20 Aug 2004, Vincent Lefevre wrote: > On 2004-08-20 11:30:44 +0200, Andy Spiegl wrote: > > Hm, wouldn't it be a nice feature in general to have zsh always remember > > the output of the last command, i.e. an automagic "keep"? > > This would be nice, but I assume that there would be similar problems > to stderr coloring (if you remember the thread...). Exactly right, Vincent. On Fri, 20 Aug 2004, Andy Spiegl wrote: > Now that I've got the list of lines (typically filenames) in $kept > how do I get them into the command line _quoted_. The best way is probably to use a completion widget. insert-kept-result () { compstate[insert]=all compadd -a kept } zle -C insert-kept-result complete-word insert-kept-result > Actually, ideally I'd like only filenames with spaces and special chars > to be quoted to avoid cluttering up the command line, but I assume > that's even tougher to do. :-( Not with completion, it isn't. As a bonus, if you type part of a word and then invoke insert-kept-result it'll only insert the subset of $kept that matches the partial word. On Fri, 20 Aug 2004, Vincent Lefevre wrote: > On 2004-08-20 14:12:02 +0200, Andy Spiegl wrote: > > Now that I've got the list of lines (typically filenames) in $kept > > how do I get them into the command line _quoted_. > > And would it be possible to get a menu, in order to select one or > several filenames manually? For that we get a little more intense: _insert_kept() { (( $#kept )) || return 1 local action zstyle -s :completion:$curcontext insert-kept action if [[ -n $action ]] then compstate[insert]=$action fi compadd -a kept } zle -C insert-kept-result complete-word _generic zstyle ':completion:insert-kept-result:*' completer _insert_kept Now you get Andy's thing with zstyle ':completion:*' insert-kept all Or you can get menu completion with zstyle ':completion:*' insert-kept menu and it does menu completion according to whatever your other usual styles are (or you can add other specific styles for this context). Just remember that TAB is still going to execute _main_complete directly, so if you start whacking TAB to cycle through the menu you won't get very far -- the normal completion context will take over and discard the list taken from $kept. You have to use the same keybinding to cycle as you did to get into the menu to begin with. Note also that if you simply stick _insert_kept into your normal completer style, the TAB key will insert values from $kept when it has a value and go on to use other completions when $kept is empty or unset. > And how about typing a pattern somewhere in the command line, then > applying a function that replaces this pattern by the matching lines > (quoted) of $kept? You'll have to be more specific. You mean something like expand-word, except that the expansion gets stashed in $kept first? I won't try to test this, but something like this should do it: _expand_word_and_keep() { function compadd() { local -a args zparseopts -E -a args A: O: if (( ! $#args )) then builtin compadd -A kept "$@" fi builtin compadd "$@" } local result kept=() _main_complete _expand result=$? unfunction compadd return $result } See the #compdef line at the top of the _expand_word function file in the distribution for how you'd plug that onto a key. Hmm, it occurs to me that I'm not sure what happens when you combine the -A and -C options of compadd ...