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

Re: Completion suggestions



On Feb 8, 10:12am, Sven Wischnowsky wrote:
> Oliver Kiddle wrote:
> > [ Quote aware completion suggestion ]
> 
> As an option, maybe. But if you have something like zsh -c "ls f<TAB>", 
> you'll want all files.

Good point. I suppose the option would have to be aware of quoting
outside the command so your example would work properly if zsh had a
compctl for -l after a -c option. I'm not sure how compctl -l deals
with quotes and -l doesn't seem to be working for me at the moment so I
can't test it.

I've made a couple of observations on differences between zsh and tcsh's
completion behaviour:
~ [68]% :> "a file"
~ [69]% less "a<tab>
tcsh completes to:
~ [69]% less "a file" _
whereas zsh completes to:
~ [69]% less "a file _
where the underscore is the cursor. I prefer tcsh's behaviour in this
case. Also, with the following:
~ [69]% less "a fi<tab>
tcsh completes as before but zsh treats us as being on the second word
so is completing files newly. I think zsh is being inconsistent as I
hope this will demonstrate:

compctl -x 'p[1]' -f - 'p[2]' -k '(a b c)' - 'p[3]' -k '(1 2 3)' -- t

While quotes are open, spaces within the quotes separate words:
~ [76]% t "a <tab>
a   b   c
~ [76]% t "a file <tab>
1   2   3
But when quotes are closed, a quoted area is all one word.
~ [76]% t "a file" <tab>
a   b   c
and backslash quoted spaces don't separate words
~ [76]% t a\ <tab>
~ [76]% t a\ file _
Note that single quotes behave in the same way as double quotes

It is difficult to say what the best thing to do is. I think zsh is
wrong because it is inconsistent but admit that it is more flexible than
tcsh because there is control of words within quotes. I don't think I've
needed this control in any of my compctls so would be in favour of
removing the inconsistency. Maybe what is needed is some way of
referencing words within quotes. e.g.
compctl -x 'p[1],qs[t]' -k '(1 2 3)' -- t
Where the q indicates that the pattern s[t] applies within the current
(quoted) word. I haven't had time to properly look at the new-style
completion yet but it might lend itself to a better solution.

> > Has any thought been given to implementing tcsh's complete=enhance
> This is what the matching control is for. In any recent enough zsh you 

fantastic thanks.

Seeing as there are no examples of matching control in compctl-examples
even though there are some in the documentation, I thought I'd
contribute my ncftp completion for it:

compctl -s '`sed -e 1,2d -e s/,.\*// < ~/.ncftp/bookmarks`' \
        -x 's[-]' -k '(a d C D f g G H L n p r R u V)' \
        - 'c[-1,-p]' -X 'Port number to dial' \
        - 'c[-1,-d]' -X 'Redial period (in seconds)' \
        - 'c[-1,-g]' -X 'No. of redials to give up after' \
        - 'c[-1,-n]' -X 'Max age of files to get (in days)' \
        - 'C[0,*.][0,*.*]' -s '`cut -d, -f2<~/.ncftp/bookmarks`' \
        -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' -- ncftp

It completes host nicknames from the ncftp bookmark file unless there is
a '.' in the word in which case full hostnames are completed.
The matching is used to treat hostnames as case-insensitive because
they are and to allow the cunning stuff with '.'. It also completes the
options but you might want to cut that out, especially as this was
written for version 3 beta which has different options to 2.x.

Oliver Kiddle



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