TAB completion of filenames beginning with colon is broken

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

TAB completion of filenames beginning with colon is broken

Jason Tyler
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-LQgi2O/bash-5.0=.
-fstack-protector-strong -Wform$
uname output: Linux jpt 5.0.0-16-generic #17-Ubuntu SMP Wed May 15 10:52:21
UTC 2019 x86_64 x86_64 x86_64 G$
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 3
Release Status: release

Description:
if a filename begins with ":", then tab completion will turn the colon into
":\:"

Repeat-By:
touch ./:
type "ls :<TAB>" to have the command completed to "ls :\:"
Reply | Threaded
Open this post in threaded view
|

Re: TAB completion of filenames beginning with colon is broken

Vishal Verma
On Thu, 2019-06-13 at 16:56 +1000, Jason Tyler wrote:

> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-LQgi2O/bash-5.0=.
> -fstack-protector-strong -Wform$
> uname output: Linux jpt 5.0.0-16-generic #17-Ubuntu SMP Wed May 15 10:52:21
> UTC 2019 x86_64 x86_64 x86_64 G$
> Machine Type: x86_64-pc-linux-gnu
>
> Bash Version: 5.0
> Patch Level: 3
> Release Status: release
>
> Description:
> if a filename begins with ":", then tab completion will turn the colon into
> ":\:"
>
> Repeat-By:
> touch ./:
> type "ls :<TAB>" to have the command completed to "ls :\:"

Known/expected behavior - this is described in 'E13' of Chet's Bash
FAQ[1]

[1]: https://tiswww.case.edu/php/chet/bash/FAQ


Reply | Threaded
Open this post in threaded view
|

Re: TAB completion of filenames beginning with colon is broken

Chet Ramey
In reply to this post by Jason Tyler
On 6/13/19 2:56 AM, Jason Tyler wrote:

> Bash Version: 5.0
> Patch Level: 3
> Release Status: release
>
> Description:
> if a filename begins with ":", then tab completion will turn the colon into
> ":\:"

This is a pretty old question, old enough to have its own entry in the
no-longer-updated bash 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    [hidden email]    http://tiswww.cwru.edu/~chet/