From: Christoph Lange <langec@gmx.de>
To: zsh-users@sunsite.auc.dk
Subject: ZLE Widget: Insert last word (except &)
Date: Tue, 11 Jul 2000 19:29:55 +0200 (CEST) [thread overview]
Message-ID: <Pine.LNX.4.10.10007111846240.1513-100000@langec.myip.org> (raw)
In-Reply-To: <20000711140506.5143gmx1@mx14.gmx.net>
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> o> o
.|. \|. \|/ // X \ | <| <|>
/\ >\ /< >\ /< >\ /< >\ /<
Mr. Asciihead learns the Macarena
Christoph Lange, langec@gmx.de, http://www.cul.de/home/yaph/, ICQ #51191833
next parent reply other threads:[~2000-07-11 18:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20000711140506.5143gmx1@mx14.gmx.net>
2000-07-11 17:29 ` Christoph Lange [this message]
2000-07-11 22:05 ` Vincent Lefevre
2000-07-11 23:04 ` Bart Schaefer
2000-07-12 8:26 ` Bart Schaefer
2000-07-12 16:38 ` Christoph Lange
2000-07-12 18:54 ` Bart Schaefer
2000-07-12 21:18 ` Christoph Lange
2000-07-12 22:33 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.10.10007111846240.1513-100000@langec.myip.org \
--to=langec@gmx.de \
--cc=duke@cyberspaces.de \
--cc=zsh-users@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).