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: Chet Ramey
Subject: Re: Completion with -W fails if words contain ':'
Date: Mon, 2 Dec 2024 11:51:40 -0800
User-agent: Mozilla Thunderbird

On 12/2/24 12:52 AM, Keith Thompson wrote:

Bash Version: 5.2
Patch Level: 32
Release Status: release

Description:
If the wordlist given to `complete -W` includes words
     containing the ':' character, completion misbehaves.

     The problem seems to occur if two or more words in the wordlist
     share a common prefix ending with ':'.  The problem does not
     occur with other characters; I've tried '/' and '_'.

This is from the (obsolete) FAQ (doc/FAQ):

E13) Why does filename completion misbehave if a colon appears in the filename?

Filename completion (and word completion in general) may appear to behave
improperly if there is a colon in the word to be completed.

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.  The original intent was to make it easy to edit
colon-separated lists (such as $PATH in bash) in various applications using
readline for input.

This is complicated by the fact that some versions of the popular
`bash-completion' programmable completion package have problems with the
default completion behavior in the presence of colons.

The current set of completion word break characters is available in bash as
the value of the COMP_WORDBREAKS variable.  Removing `:' from that value is
enough to make the colon not special to completion:

COMP_WORDBREAKS=${COMP_WORDBREAKS//:}

You can also quote the colon with a backslash to achieve the same result
temporarily.

--
``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/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

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