Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bug#519535: history expansion: modifier completion missing
- X-seq: zsh-workers 26746
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: Bug#519535: history expansion: modifier completion missing
- Date: Tue, 17 Mar 2009 09:57:17 +0000
- In-reply-to: <090316194434.ZM16487@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <20090313105555.GA19025@xxxxxxxxxxxxxxxxxxxxxxxxxx> <20090315062253.GB14010@xxxxxxxx> <20090316181852.27e9420d@news01> <090316194434.ZM16487@xxxxxxxxxxxxxxxxxxxxxx>
On Mon, 16 Mar 2009 19:44:34 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> [-bugs.debian.org]
>
> On Mar 16, 6:18pm, Peter Stephenson wrote:
> }
> } I thought this was going to be harder than it turned out to be; as you can
> } see it's really quite simple, particularly since I already wrote modifer
> } completion and it would appear had the foresight to make it handle the
> } history case.
>
> Nit-pick: This doesn't handle the new :a/:A modifiers.
I've fixed that.
> Other nit-pick about :a itself -- get a load of this:
>
> torch% echo foo
> torch% !!:a
> /usr/local/src/zsh/zsh-build/echo foo
> zsh: no such file or directory: /usr/local/src/zsh/zsh-build/echo
>
> That's almost certainly not the intended behavior ... is it?
It depends what you mean by "intended": Michael did say the operation
didn't take account of whether the file existed (but I didn't document
this), and there was never any special behaviour for command words. You
could make it work like "=", I suppose, but that's an extension.
> Replace :a
> with :h or :t there and you get "modifier failed" (which seems odd as
> well, but ...).
I think it's always done that, although that doesn't mean it's necessarily
useful. Logically, it seems to me that for :h to fail is probably useful
(there's no directory part, so you won't get it) but for :t to fail is less
so, since you've already got a perfectly good non-directory part (even it
happens to be a directory, this isn't VMS). So we could probably change
that without anyone complaining.
> I don't know how the generic quoting code plays in, but I suspect this
> is done this way *because* history expansion takes place so early. If
> it looks like a history expansion and it got this far, then it must be
> a *failed* history expansion and needs to be quoted if it matches any
> other completion -- otherwise the history expansion will fail *again*
> after accept-line, and spoil the whole command.
That's quite possible. The quote code is hair-raising enough (see utils.c
around line 4504) that it's quite hard to tell. It's being called from
multiquote() within callcompfunc() in compcore.c, which is called for all
top-level completion widgets. The commenting in that last function is
quite amusing in an infuriating sort of way: there are three, and all of
them are in blocks marked with "#if 0".
> } I think -z $compstate[quote] ensures we're not already doing something
> } clever inside nested quotes, which would mean the expression couldn't be a
> } history expansion. I think.
>
> History expansion occurs inside double quotes, though, so if the quote
> state is double-quote then ... er, um ... perhaps it's necessary to
> run compstate -q and examine $compstate[all_quotes] ...
Hmm... I deliberately didn't make the test too hairy, so it only completes
at the start of a word, but it looks like it's not too hard to fix the
simplest case of double quoting.
Index: Completion/Base/Core/_normal
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_normal,v
retrieving revision 1.5
diff -u -r1.5 _normal
--- Completion/Base/Core/_normal 16 Mar 2009 18:29:39 -0000 1.5
+++ Completion/Base/Core/_normal 17 Mar 2009 09:42:27 -0000
@@ -13,7 +13,9 @@
# $PREFIX has a quoted form of the !, so we can't test that
# (it might the start of a real argument), but words has the
# raw McCoy.
-if [[ -o BANG_HIST && $words[CURRENT] = \!*: && -z $compstate[quote] ]]; then
+if [[ -o BANG_HIST &&
+ ( ( $words[CURRENT] = \!*: && -z $compstate[quote] ) ||
+ ( $words[CURRENT] = \"\!*: && $compstate[all_quotes] = \" ) ) ]]; then
# This looks like a real history expansion; in that case
# we'd better put the !'s back the way pfalstad intended.
PREFIX=${PREFIX//\\!/!}
Index: Completion/Zsh/Type/_history_modifiers
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Type/_history_modifiers,v
retrieving revision 1.2
diff -u -r1.2 _history_modifiers
--- Completion/Zsh/Type/_history_modifiers 23 Feb 2008 18:34:02 -0000 1.2
+++ Completion/Zsh/Type/_history_modifiers 17 Mar 2009 09:42:27 -0000
@@ -64,6 +64,8 @@
)
if (( ! global )); then
list+=(
+ "a:absolute path"
+ "A:absolute path resolving symbolic links"
"g:globally apply s or &"
"h:head - strip trailing path element"
"t:tail - strip directories"
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author