zsh-users
 help / color / mirror / code / Atom feed
* Re: Completion of CLI parameters
       [not found] <4me190pohevfcnoecm43f7ab9cclh3233g@4ax.com>
@ 2004-04-29 11:40 ` Peter Stephenson
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2004-04-29 11:40 UTC (permalink / raw)
  To: zsh-users

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@csr.com>                  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
**********************************************************************


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of CLI parameters
  2004-05-01 17:50       ` Bart Schaefer
@ 2004-05-02 15:35         ` zzapper
  0 siblings, 0 replies; 8+ messages in thread
From: zzapper @ 2004-05-02 15:35 UTC (permalink / raw)
  To: zsh-users

On Sat, 1 May 2004 17:50:52 +0000,  wrote:

>On May 1,  3:14pm, zzapper wrote:
>} Subject: Re: Completion of CLI parameters
>}
>} >#autoload
>} ># Name this file expand-args-of and place it in a $fpath directory, and
>} ># then add these commands to .zshrc:
>} >#  zle -C expand-args-of complete-word _generic
>} >#  zstyle ':completion:expand-args-of::::' completer expand-args-of
>} >#  bindkey '^x^a' expand-args-of
>} 
>} This one just beeps at me?!?
>
>Is it possible that expand-args-of is not being autoloaded?
>
>It's compinit that processes the #autoload directive, so you either have
>to manually autoload it or re-run compinit or start a fresh zsh before it
>will work.  I should have mentioned that.  You may also have to remove
>your ~/.zcompdump file and let it be rebuilt.

Bart,
deleted ~/.zcompdump . launched fresh dos-zsh-window. ~/.zcompdump
does not re-appear. 

It still only beeps for me. Tried launching everything manually as
well.

I probably need a complete idiots guide, like how is this supposed to
work.. I got Peter Stevenson's widget working but inconsistently
zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of CLI parameters
  2004-05-01 14:14     ` zzapper
@ 2004-05-01 17:50       ` Bart Schaefer
  2004-05-02 15:35         ` zzapper
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2004-05-01 17:50 UTC (permalink / raw)
  To: zsh-users

On May 1,  3:14pm, zzapper wrote:
} Subject: Re: Completion of CLI parameters
}
} >#autoload
} ># Name this file expand-args-of and place it in a $fpath directory, and
} ># then add these commands to .zshrc:
} >#  zle -C expand-args-of complete-word _generic
} >#  zstyle ':completion:expand-args-of::::' completer expand-args-of
} >#  bindkey '^x^a' expand-args-of
} 
} This one just beeps at me?!?

Is it possible that expand-args-of is not being autoloaded?

It's compinit that processes the #autoload directive, so you either have
to manually autoload it or re-run compinit or start a fresh zsh before it
will work.  I should have mentioned that.  You may also have to remove
your ~/.zcompdump file and let it be rebuilt.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of CLI parameters
  2004-04-29 14:59   ` Bart Schaefer
@ 2004-05-01 14:14     ` zzapper
  2004-05-01 17:50       ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: zzapper @ 2004-05-01 14:14 UTC (permalink / raw)
  To: zsh-users

On Thu, 29 Apr 2004 14:59:58 +0000,  wrote:

>On Apr 29,  1:56pm, Peter Stephenson wrote:
>}
>} autoload -U insert-args-of
>} zle -N insert-args-of
>} bindkey '^x^a' insert-args-of
>
>Oliver would say this was crying out to be a _generic completer; here's
>a trivial stab at one.  However, the right thing would be for _expand to
>recognize a zstyle -- perhaps named "expander" -- that would supply a
>function to produce expansions, and to try calling that before falling
>back on the usual shell expansions.  That way we'd get the full power of
>all the other styles recognized by _expand.
>
>The following suffers from the usual problems of menus that may contain
>multi-line structures, I haven't done anything to address that.
>
>#autoload
># Name this file expand-args-of and place it in a $fpath directory, and
># then add these commands to .zshrc:
>#  zle -C expand-args-of complete-word _generic
>#  zstyle ':completion:expand-args-of::::' completer expand-args-of
>#  bindkey '^x^a' expand-args-of
>
>local pat=$words[CURRENT]
>local -a exp
>
>if ((CURRENT > 1))
>then
>  # Remove the first * here to match on command name only
>  exp=( $history[(R)*${(q)pat}*] )
>  exp=( ${exp#*[[:space:]]} )
>else
>  exp=( $history[(R)${(q)pat}*] )
>fi
>compadd -UQ -a exp
>compstate[insert]=menu
>
>#end of expand-args-of

This one just beeps at me?!?

zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of CLI parameters
  2004-04-29 12:56 ` Peter Stephenson
@ 2004-04-29 14:59   ` Bart Schaefer
  2004-05-01 14:14     ` zzapper
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2004-04-29 14:59 UTC (permalink / raw)
  To: zsh-users

On Apr 29,  1:56pm, Peter Stephenson wrote:
}
} autoload -U insert-args-of
} zle -N insert-args-of
} bindkey '^x^a' insert-args-of

Oliver would say this was crying out to be a _generic completer; here's
a trivial stab at one.  However, the right thing would be for _expand to
recognize a zstyle -- perhaps named "expander" -- that would supply a
function to produce expansions, and to try calling that before falling
back on the usual shell expansions.  That way we'd get the full power of
all the other styles recognized by _expand.

The following suffers from the usual problems of menus that may contain
multi-line structures, I haven't done anything to address that.

#autoload
# Name this file expand-args-of and place it in a $fpath directory, and
# then add these commands to .zshrc:
#  zle -C expand-args-of complete-word _generic
#  zstyle ':completion:expand-args-of::::' completer expand-args-of
#  bindkey '^x^a' expand-args-of

local pat=$words[CURRENT]
local -a exp

if ((CURRENT > 1))
then
  # Remove the first * here to match on command name only
  exp=( $history[(R)*${(q)pat}*] )
  exp=( ${exp#*[[:space:]]} )
else
  exp=( $history[(R)${(q)pat}*] )
fi
compadd -UQ -a exp
compstate[insert]=menu

#end of expand-args-of

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of CLI parameters
       [not found] <a5u190lnjueh9jiu4ci6bq5uimo4d5tu37@4ax.com>
@ 2004-04-29 12:56 ` Peter Stephenson
  2004-04-29 14:59   ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2004-04-29 12:56 UTC (permalink / raw)
  To: zsh-users

zzapper wrote:
> Sorry to abuse your helpfullness but could you give me a complete
> "idiots guide".
> 
> I presumably need a 
> zle
> bindkey
> function insert-args-of 
> 
> Do these all go in my startup files? (I use .zshenv)

(Don't copy zsh-workers on messages to zsh-users.  I think it's smart
enough to sort it out but you shouldn't anyway.)

You need in to save what I sent you on a directory in your $fpath.

In your start-up file you will have something like

autoload -U insert-args-of
zle -N insert-args-of
bindkey '^x^a' insert-args-of

See various similar examples in the zshcontrib manual page.

-- 
Peter Stephenson <pws@csr.com>                  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
**********************************************************************


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion of CLI parameters
  2004-04-28 15:56 zzapper
@ 2004-04-28 17:39 ` Peter Stephenson
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2004-04-28 17:39 UTC (permalink / raw)
  To: zsh-users

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 numb
> er?>

cmdy !?cmd1?:*<TAB>

(or use the magic-space binding).

-- 
Peter Stephenson <pws@csr.com>                  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
**********************************************************************


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Completion of CLI parameters
@ 2004-04-28 15:56 zzapper
  2004-04-28 17:39 ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: zzapper @ 2004-04-28 15:56 UTC (permalink / raw)
  To: zsh-users

Hi,

> cmd1 p1 p2 p3
> cmd2
....
...

> cmdx p4 p5
> cmdy <I would like to complete to get p1 p2 p3 without knowing history number?>

Is this possible?

zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-05-02 15:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <4me190pohevfcnoecm43f7ab9cclh3233g@4ax.com>
2004-04-29 11:40 ` Completion of CLI parameters Peter Stephenson
     [not found] <a5u190lnjueh9jiu4ci6bq5uimo4d5tu37@4ax.com>
2004-04-29 12:56 ` Peter Stephenson
2004-04-29 14:59   ` Bart Schaefer
2004-05-01 14:14     ` zzapper
2004-05-01 17:50       ` Bart Schaefer
2004-05-02 15:35         ` zzapper
2004-04-28 15:56 zzapper
2004-04-28 17:39 ` Peter Stephenson

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).