Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 805
wizmer Avatar asked Apr 23 '15 12:04

wizmer


People also ask

What is bash auto completion?

Bash completion is a bash function that allows you to auto complete commands or arguments by typing partially commands or arguments, then pressing the [Tab] key. This will help you when writing the bash command in terminal.

How do I make fish like bash?

Fish makes this really easy since it looks for its completion scripts, auto loaded, functions, and other config files relative to where you install it. So just ./configure --prefix=$HOME/fish; make install . Then symlink ~/bin/fish to ~/fish/bin/fish or add ~/fish/bin to your PATH.

Where do bash completion files go?

Put them in the completions subdir of $BASH_COMPLETION_USER_DIR (defaults to $XDG_DATA_HOME/bash-completion or ~/. local/share/bash-completion if $XDG_DATA_HOME is not set) to have them loaded automatically on demand when the respective command is being completed.


1 Answers

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

like image 190
Boop Avatar answered Oct 16 '22 11:10

Boop