scop / bash-completion

Programmable completion functions for bash
GNU General Public License v2.0
2.8k stars 376 forks source link

fix(ip): Quote network namespace names #1140

Closed yedayak closed 3 months ago

yedayak commented 3 months ago

Network namespaces can have spaces in them, which lead to incorrect completions in that case. Fix it by calling _comp_quote on all namespace names.

There are probably better ways to do this than overwriting $COMPREPLY, but I couldn't find one.

yedayak commented 3 months ago

I moved to using _comp_quote_compgen which seems more appropriate. This also allowed me to remove the %q printf

akinomyoga commented 3 months ago

Thank you for updating!

I moved to using _comp_quote_compgen which seems more appropriate.

Do you have an explanation for it? I feel _comp_quote_compgen is not the one because it is intended for cur (i.e., the string used to filter the generated completions) but not for the generated completions. It does some extra modifications that seem inappropriate to apply to the generated completions.

yedayak commented 3 months ago

Thank you for updating!

I moved to using _comp_quote_compgen which seems more appropriate.

Do you have an explanation for it? I feel _comp_quote_compgen is not the one because it is intended for cur (i.e., the string used to filter the generated completions) but not for the generated completions. It does some extra modifications that seem inappropriate to apply to the generated completions.

From what I tested it seems _comp_quote adds single quotes unconditionally, while _comp_quote_compgen quotes spaces and such with backslashes. Also, using _comp_quote just doesn't seem to actually complete, it completes ' but that's it (this is with _comp_quote):

$ ip netns list
blah bah
rgergerg
$ ip netns delete # Completes '
$ ip netns delete '<TAB>
'blah bah'  'rgergerg'
$ ip netns delete 'b<TAB>  # Completes nothing
akinomyoga commented 3 months ago

From what I tested it seems _comp_quote adds single quotes unconditionally, while _comp_quote_compgen quotes spaces and such with backslashes. Also, using _comp_quote just doesn't seem to actually complete, it completes ' but that's it (this is with _comp_quote):

What I suggested in https://github.com/scop/bash-completion/pull/1140#discussion_r1535012572 is to use printf %q (but not _comp_quote). Do you have an explanation for the reason that _comp_quote_compgen is preferred over printf %q? In particular, this part and this part are the differences from printf %q, but how are they used in the present case?

yedayak commented 3 months ago

From what I tested it seems _comp_quote adds single quotes unconditionally, while _comp_quote_compgen quotes spaces and such with backslashes. Also, using _comp_quote just doesn't seem to actually complete, it completes ' but that's it (this is with _comp_quote):

What I suggested in #1140 (comment) is to use printf %q (but not _comp_quote). Do you have an explanation for the reason that _comp_quote_compgen is preferred over printf %q? In particular, this part and this part are the differences from printf %q, but how are they used in the present case?

OK, I didn't get that. Just using printf %q seems to work fine, pushed a version with that