Bash – colorize bash_completion

bashcolors

When I type grep and then press TAB twice, bash_completion will list files and directories in current directory. It will also complete filenames when I type initial letter. That is all very nice, the only problem is that when the directory contains many files and subdirectories, it can be quite chaotic and disorganized.

It would help very much if bash_completion could at least color directories differently, similarly to what ls -lA does.

Is this possible?

EDIT:

this is what my sample bash_completion config file looks like:

if [[ ${cur} == -* ]] ; then
    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    return 0

else
    _filedir
fi

Best Answer

There is no out of the box feature like this in the current version of Bash, you can do this using zsh, it's there by default.

One of the tools related to the completion is called compgen. You can finagle it to show commands correctly colorized, but this is a hack and not that practically useful.

$ compgen -W "$(ls --color=always *)"

That will properly list the files out colorized, but it's getting the color from ls, so I wouldn't consider this native coloring by auto_completion.

References