wizmer
wizmer

Reputation: 930

Bash auto-completion highlighting

I'd like to know if it is possible to make bash auto-completion highlight the matched part of the auto-complete suggestion.

For example, I am have directories with files such as these:

LSFJOB_647169535/ LSFJOB_647158534/

In this case, if I type LSF and hit Tab, then I get:

LSFJOB_6471

But then I have to focus hard to get which character should I type next.

I'd like bash to suggest me something like:

LSFJOB_647169535/ LSFJOB_647158534/

or

LSFJOB_647169535/ LSFJOB_647158534/

Do you know a way of doing it?

Upvotes: 11

Views: 4334

Answers (2)

Benjamin W.
Benjamin W.

Reputation: 52142

Instead of colored-completion-prefix, which requires Bash 4.4, you could add the older (Bash 4.0)

set completion-prefix-display-length 2

to your ~/.inputrc (see manual). This replaces any common prefix longer than 2 characters with an ellipsis when showing the completions:

$ ls
LSFJOB_647158534  LSFJOB_647169535
$ cd LSFJOB_6471<tab>
...58534/ ...69535/

Upvotes: 4

Boop
Boop

Reputation: 1386

That is a good question!

Dennis Williamson already answered it there (SuperUser).

So it turns out that there is a "ReadLine Variable" that does exactly that: colored-completion-prefix.

Sadly it's only available in Bash v4.4 :c Link to the diff

You can check its value with bind -v|grep color

I tried to play with compgen but it appears that it strips colors away /:

Upvotes: 5

Related Questions