Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: history menu completion?
- X-seq: zsh-users 5261
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: <vts@xxxxxxxxxxxxxxxxxxxx>, <zsh-users@xxxxxxxxxx>
- Subject: Re: history menu completion?
- Date: Sat, 17 Aug 2002 03:48:43 +0000
- In-reply-to: <Pine.LNX.4.33L2.0208161840130.28906-100000@xxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <Pine.LNX.4.33L2.0208161840130.28906-100000@xxxxxxxxxxxxxxxxxxxx>
On Aug 16, 6:51pm, <vts@xxxxxxxxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author