24

Is there a way to get colored output when using tab completion in a terminal? My colors are fine everywhere else so I know that I've enabled a color terminal successfully.

Using bash in Ubuntu (10.10).

1
  • How do you specify a "colored output when using tab completion"?
    – slhck
    Feb 27, 2011 at 19:51

2 Answers 2

31

There's no facility within Bash to color output during completion as there is in fish and zsh. One could write completion functions that output color control sequences, but you'd have to maintain copies of the proposed completions with and without color codes or strip the out when the user makes a selection since Bash uses the selection directly normally and the color codes would get in the way.

If this is an important feature for you, I would recommend that you consider using zsh.

Update

Bash 4.3 readline adds a variable that enables color for tab completion to show different colors for executable files, directories, etc., during tab completion:

colored-stats

Readline in the upcoming Bash 4.4 adds a variable which enables color to indicate the matching portion of the string during tab completion.

colored-completion-prefix

You can see the values of these variables using

bind -v | grep color

To set them, add lines(s) to your ~/.inputrc file such as:

set colored-stats on
13
  • 1
    @Ryan: Zsh is quite compatible with Bash. You would probably find the switch to be fairly easy. It has a lot of powerful features that Bash doesn't have (or you have to use external utilities for). There are only a few things that are significantly different in the basics. An example is that array indexes are one-based instead of zero-based, but there's a setting that affects that. I only use zsh occasionally, though. Feb 27, 2011 at 20:30
  • 1
    @AstroFloyd: From the Bash Manua: "The color definitions are taken from the value of the LS_COLORS environment variable." The documentation for that variable is here. There isn't a setting for man pages, so you'll need to look at where your LS_COLORS gets set and find the color combination that corresponds and change it. On my system, man page names don't get colored when being tab completed (and broken symlinks, while red-on-gray in ls output, ... Feb 19, 2018 at 17:10
  • 1
    ... are light-blue like valid symlinks during tab-completion). Feb 19, 2018 at 17:11
  • 1
    @AndyCarlson: Does bind -v | grep color show both set colored-completion-prefix on and set colored-stats on? If so, what happens when you type the letter a followed by pressing tab twice? If you've added the settings to your ~/.inputrc but haven't started a new terminal or haven't executed re-read-init-file by pressing control-x control-r then the settings won't have taken effect. Mar 28, 2019 at 12:59
  • 2
    @AndyCarlson What is output at a bash prompt when you press ctrl-x ctrl-v? Mar 28, 2019 at 15:15
4

I do not know about completion colors for command options and arguments but for filename and directories, according to (https://unix.stackexchange.com/a/133866) user495470 states that in Bash 4.3 and later you can add set colored-stats on to ~/.inputrc to get colored completion when you do ls <tab>.

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.