9

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
  • 1
    I don't know if this is possible in bash but it is the default behavior in zsh. – terdon Jan 29 '14 at 22:27
  • 1
    in case it is not obvious, I am looking for a solution for bash – Martin Vegter Feb 2 '14 at 14:20
  • What file are you showing? – terdon Feb 2 '14 at 15:29
7

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

  • please see my edit. I don't have any ls in my bash_completion config files. Looks like there is a function _filedir which lists files. – Martin Vegter Jan 29 '14 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.