bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Completion with -W fails if words contain ':'


From: Keith Thompson
Subject: Re: Completion with -W fails if words contain ':'
Date: Tue, 3 Dec 2024 20:48:22 -0800

On Tue, Dec 3, 2024 at 10:20 AM Chet Ramey <chet.ramey@case.edu> wrote:
>
> 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.

Sure, but that would affect all completions. I only want to change how
completions
work for my one custom command.

> > 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:

When you wrote "on the command line", I thought you were referring to
the command line with the complete" command.  If you meant escaping
colons on the command line with the "say" command, that's not useful
to me (and I haven't been able to get it to work anyway).

Can you clarify with an example? So far, I haven't found a solution
that's easier than just changing the syntax of my command to use '/'
rather than ':' (which I've done).

>  >> 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.).

It looks like "-o filenames" is pretty close to what I want. I'd
rather not have the backslashes appear when I type <TAB>, but I
can live with that.

Thanks.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]