[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Completion with -W fails if words contain ':'
From: |
Chet Ramey |
Subject: |
Re: Completion with -W fails if words contain ':' |
Date: |
Tue, 3 Dec 2024 10:20:33 -0800 |
User-agent: |
Mozilla Thunderbird |
On 12/2/24 7:29 PM, Keith Thompson wrote:
OK, that explains the problem, and I have a workaround.
(Background: I have a personal tool that uses "foo:bar" syntax for
some of its arguments. I've modified the tool to use "foo/bar
instead.)
An easier workaround might have been removing `:' from COMP_WORDBREAKS.
Escaping the colons with backslashes doesn't seem to work:
You have to quote the colons on the command line so readline breaks the
words it sends to programmable completion like you want. That's what this
FAQ text (which predates programmable completion) means:
>> The colon is special to readline's word completion code: it is one of the
>> characters that breaks words for the completer. Readline uses these
characters
>> in sort of the same way that bash uses $IFS: they break or separate the
words
>> the completion code hands to the application-specific or default word
>> completion functions.
$ echo $BASH_VERSION
5.2.32(1)-release
$ echo $COMP_WORDBREAKS
"'@><=;|&(:
$ say() { echo "$@" ; }
$ complete -r
$ complete -W "abc\:abc abc\:xyz" say
You don't need to quote the colons here, but it doesn't end up hurting
anything.
$ complete
complete -W 'abc\:abc abc\:xyz' say
$ say abc:abc:abc:abc:abc: # hitting TAB multiple times
You haven't quoted the colons here. If you don't, readline will break
the word at the colon and send the empty string to programmable
completion.
You can use the `-o filenames' option to complete to have programmable
completion (and readline) quote the matches appropriately for you. If
you don't want the full filename treatment, bash-5.3 will have the
`-o fullquote' option to just do quoting without any of the other
filename actions (appending a slash, etc.).
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature