Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Filename completion and quotes



On Feb 23,  6:49pm, Joke de Buhr wrote:
}
} is there a way to make filename completion use double quotes instead of 
} blackshlash quoting?

Background:  Completion wants to incrementally append stuff to the ZLE
buffer whenever it can; anytime you have a case where it inserts into
or changes the part of the word that's already there, a programmer must
have done the extra work (in the script that generates the list of the
possible completions) to instruct it to do so, and to "manually" limit
the set of matches to the appropriate replacement (instead of allowing
the internals to automatically filter against the prefix).

So you can't just turn that behavior on and off at will, and hence why
it can do what you want provided that the initial quote is already in
the prefix.

However, what you CAN do is create your own ZLE widget that wraps
around completion and fixes things up.  There is an example of this
called quote-and-complete-word in the set of functions supplied along
with the shell.  What this function actually does is rewrite the line
to put the quote at the beginning of the word, and THEN run normal
completion, and then possibily remove the quote again -- so it does
not do exactly what you've asked for, because the quotes will remain
in cases where it's not strictly necessary.

    autoload -U quote-and-complete-word
    zle -N quote-and-complete-word

and now bind this to a key (I don't recommend going directly for the
tab key on the first try).

This function is meant as an example and isn't documented because it
has oddball edge-case behaviors and doesn't work well with approximate
completion, e.g., when correcting other mistakes on the line.

It also may be tickling some bugs in zsh ... hey, PWS:

If I invoke quote-and-complete-word via execute-named-command on an
empty buffer, I get this:

schaefer<525> 11: ../../../zsh-4.0/Src/Zle/zle_tricky.c:661: BUG: 0 <= wb <=
zlemetacs <= we is not true!

The same error does not occur when invoking it via a direct binding.



Messages sorted by: Reverse Date, Date, Thread, Author