From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5521 invoked from network); 11 Jul 2000 18:03:35 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 11 Jul 2000 18:03:35 -0000 Received: (qmail 11901 invoked by alias); 11 Jul 2000 18:03:13 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3265 Received: (qmail 11893 invoked from network); 11 Jul 2000 18:03:12 -0000 Date: Tue, 11 Jul 2000 19:29:55 +0200 (CEST) From: Christoph Lange Reply-To: Christoph Lange To: zsh-users@sunsite.auc.dk Subject: ZLE Widget: Insert last word (except &) In-Reply-To: <20000711140506.5143gmx1@mx14.gmx.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Hi there, I found it annoying that the widget insert-last-word inserts `&' if the previous command was a background job. I'd rather like the last word *before* `&' to be inserted. So I wrote a custom widget: smart-insert-last-word() { emulate -L zsh setopt extendedglob if [[ -n "$NUMERIC" ]] then zle insert-last-word -n $NUMERIC else lastcmd=`fc -n -l -1` lastcmd=${lastcmd%%[[:space:]]#} if [[ $lastcmd[$#lastcmd] == '&' && $lastcmd[$#lastcmd-1] != '\' ]] then zle insert-last-word -n 2 else zle insert-last-word fi fi } zle -N smart-insert-last-word bindkey "^[." smart-insert-last-word bindkey "^[_" smart-insert-last-word If any numeric argument is given, the original function is called with that argument. Otherwise, the previous command ist determined. If it ends with `&', insert-last-word is invoked with an argument of 2, which inserts the last but one word. Example: % myeditor *.txt & % cp _ # press [Alt+.], _ is the cursor % cp *.txt_ # result Hope you find it useful. Christoph -- o o o o o o> o .|. \|. \|/ // X \ | <| <|> /\ >\ /< >\ /< >\ /< >\ /< Mr. Asciihead learns the Macarena Christoph Lange, langec@gmx.de, http://www.cul.de/home/yaph/, ICQ #51191833