zsh-users
 help / color / mirror / code / Atom feed
* history menu completion?
@ 2002-08-16 23:51 vts
  2002-08-17  3:48 ` Bart Schaefer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vts @ 2002-08-16 23:51 UTC (permalink / raw)
  To: zsh-users


Here is a scenario:

$ somecommand -with -fancy /options/and/a/long/path
$ somecommand -with -more -fancy /options/and/another/long/path
.

Now, if I do:

$ !somecom<TAB>

I'll get the following

$ somecommand -with -more -fancy /options/and/another/long/path

At this point, I would like to be able to hit <TAB> again to get:

$ somecommand -with -fancy /options/and/a/long/path

the same way it works for ambiguous filename completion.  Searches
have failed me: Is there a way to do this with zsh?

If not, there should be!




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

* Re: history menu completion?
  2002-08-16 23:51 history menu completion? vts
@ 2002-08-17  3:48 ` Bart Schaefer
  2002-08-17  5:01 ` Wayne Davison
  2002-08-17  8:50 ` Darren Greaves
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2002-08-17  3:48 UTC (permalink / raw)
  To: vts, zsh-users

On Aug 16,  6:51pm, <vts@veritas.uchicago.edu> wrote:
} 
} $ !somecom<TAB>
} 
} I'll get the following
} 
} $ somecommand -with -more -fancy /options/and/another/long/path
} 
} At this point, I would like to be able to hit <TAB> again to get:
} 
} $ somecommand -with -fancy /options/and/a/long/path

You're confusing expansion and completion.

When completion is invoked, zsh first attempts history expansion on the
command line.  Only if that fails to change anything is actual completion
attempted.  (If the keybinding is "expand-or-complete" then the other
expansions -- parameters, file globbing, etc. -- are also tried before
completion.)  So the effect you see on the first TAB is expansion, and
the fact that there was a history reference is long forgotten by the
time you hit the second TAB.

It's really not possible to do this any other way, because the number
of different ways to reference the history -- searches with !?pat?, the
word numbers with !:2, etc. -- plus the possibility of having several
different history references on the command line at the same time when
completion is started, make it potentially impossible to "find another
line matching the history references that expanded to give this one."

If what you want is to search the history, you should be using some of
ZLE's many history-search bindings.

You can write your own zle widget that invokes history search when you
press TAB; e.g.:

    function history-or-complete {
	setopt localoptions noksharrays
	typeset -gH __history_completing
	if [[ $LBUFFER[1] == '!' ]]
	then
	    LBUFFER[1]=''
	    local ret=0
	    if zle history-beginning-search-backward
	    then
		__history_completing=history-beginning-search-backward
	    else
	    	zle complete-word || ret=$?
		LBUFFER='!'"$LBUFFER"
	    fi
	    return ret
	elif [[ $LASTWIDGET == history-or-complete ]]
	then
	    zle $__history_completing
	else
	    __history_completing=complete-word
	    zle complete-word
	fi
    }
    zle -N history-or-complete
    bindkey '\t' history-or-complete

If this doesn't cut it, try replacing history-beginning-search-backward
with history-search-backward, or whatever other builtin widget does the
thing most like what you want

-- 
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] 4+ messages in thread

* Re: history menu completion?
  2002-08-16 23:51 history menu completion? vts
  2002-08-17  3:48 ` Bart Schaefer
@ 2002-08-17  5:01 ` Wayne Davison
  2002-08-17  8:50 ` Darren Greaves
  2 siblings, 0 replies; 4+ messages in thread
From: Wayne Davison @ 2002-08-17  5:01 UTC (permalink / raw)
  To: vts; +Cc: zsh-users

On Fri, 16 Aug 2002 vts@veritas.uchicago.edu wrote:
> $ somecommand -with -fancy /options/and/a/long/path
> $ somecommand -with -more -fancy /options/and/another/long/path
> $ !somecom<TAB>

How about typing the following instead?

$ somecom<ESC>p

Then, repeat the <ESC>p again to visit each prior command that started
with "somecom".

..wayne..


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

* Re: history menu completion?
  2002-08-16 23:51 history menu completion? vts
  2002-08-17  3:48 ` Bart Schaefer
  2002-08-17  5:01 ` Wayne Davison
@ 2002-08-17  8:50 ` Darren Greaves
  2 siblings, 0 replies; 4+ messages in thread
From: Darren Greaves @ 2002-08-17  8:50 UTC (permalink / raw)
  To: zsh-users

Hi, here is what I do to achieve what you want.

I bound history-beginning-search-forward to F2 and
history-beginning-search-backward to F3.

Then, when I type a command that I want to recall from history, I simply
type enough to match the history (usually just the command without any
parameters) then press F2 or F3 to cycle through all the history matches
for that command.

Example.
$ somecom<F2> matches
$ somecommand -with -fancy /options/and/a/long/path

but the cursor stays in place and you can press F2 again and it will
match:
$ somecommand -with -more -fancy /options/and/another/long/path
and so on...

I read about it a while back on this list and it has changed my life.
:-)


Darren.


On Fri, Aug 16, 2002 at 06:51:57PM -0500, vts@veritas.uchicago.edu wrote:
> 
> Here is a scenario:
> 
> $ somecommand -with -fancy /options/and/a/long/path
> $ somecommand -with -more -fancy /options/and/another/long/path
> .
> 
> Now, if I do:
> 
> $ !somecom<TAB>
> 
> I'll get the following
> 
> $ somecommand -with -more -fancy /options/and/another/long/path
> 
> At this point, I would like to be able to hit <TAB> again to get:
> 
> $ somecommand -with -fancy /options/and/a/long/path
> 
> the same way it works for ambiguous filename completion.  Searches
> have failed me: Is there a way to do this with zsh?
> 
> If not, there should be!
> 
> 
> 

-- 
Burns:    Who was that young hellcat, Smithers?
Smithers: Homer Simpson, sir.
Burns:    Simpson, eh?  I'll remember that name...
Darren Greaves <darren@krapplets.org> - http://boncey.org/


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

end of thread, other threads:[~2002-08-17  8:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-16 23:51 history menu completion? vts
2002-08-17  3:48 ` Bart Schaefer
2002-08-17  5:01 ` Wayne Davison
2002-08-17  8:50 ` Darren Greaves

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