Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Completion of CLI parameters
- X-seq: zsh-users 7419
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Completion of CLI parameters
- Date: Thu, 29 Apr 2004 12:40:15 +0100
- In-reply-to: "zzapper"'s message of "Thu, 29 Apr 2004 09:35:31 BST." <4me190pohevfcnoecm43f7ab9cclh3233g@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
zzapper wrote:
> On Wed, 28 Apr 2004 18:39:05 +0100, wrote:
>
> >zzapper wrote:
> >> Hi,
> >>
> >> > cmd1 p1 p2 p3
> >> > cmd2
> >> ....
> >> ...
> >>
> >> > cmdx p4 p5
> >> > cmdy <I would like to complete to get p1 p2 p3 without knowing history n
> umb
> >> er?>
> >
> >cmdy !?cmd1?:*<TAB>
> >
> That's cool, bit of a type-fest though!!
Here's a zle widget called insert-args-of which does the whole thing.
Type `cmd1' and execute the widget. Actually, !? searches for a string
inside the command, so it's more powerful than I suggested. What you
asked for works without the `?'s.
Works without `banghist' in use, since turning that on locally seems to
be sufficient.
#start
# Zle widget to look at a string and replace it with the arguments
# of the last command in the history containing that string.
emulate -L zsh
setopt banghist
# Remember position
integer pos=$CURSOR
# Find start of word. Just use whitespace.
while [[ $CURSOR -gt 1 && $LBUFFER[-1] != [[:space:]] ]]; do
(( CURSOR-- ))
done
# Insert history substitution characters
LBUFFER+="!?"
# Go back to start position, remembering extra characters.
(( CURSOR = pos + 2 ))
# Search for end of word.
while [[ -n $RBUFFER && $RBUFFER[1] != [[:space:]] ]]; do
(( CURSOR++ ))
done
# Insert trailing history substitution characters.
LBUFFER+="?:*"
# Use magic-space to expand the history substitution.
zle magic-space
#end
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
www.mimesweeper.com
**********************************************************************
Messages sorted by:
Reverse Date,
Date,
Thread,
Author