is there a way to set coloring for cd tab complete?

13,141

Solution 1

With readline 6.3 and later you can add

set colored-stats on

to ~/.inputrc.

See https://tiswww.case.edu/php/chet/readline/rluserman.html:

colored-stats

If set to `on', Readline displays possible completions using different colors to indicate their file type. The color definitions are taken from the value of the LS_COLORS environment variable. The default is `off'.

You can use http://geoff.greer.fm/lscolors/ to generate both LS_COLORS (which is used by GNU ls and colored-stats) and LSCOLORS‏ (which is used by BSD ls).

Solution 2

I don't know if it is in bash (the default shell). It is possible in zsh (a more powerful shell than bash, available on most unices including Ubuntu but often not installed by default).

The first time you run zsh, it will offer to create a configuration file (~/.zshrc) for you. The default configuration is a bit barren, for historical compatibility. For colored completion listings, select 2 to configure the “new completion system”, then 2 again to tune it; in the compinstall menu, select 3 to set styles for displaying completions and 3 then 1 to enable colored completions and finally 2 to use the same colors as ls.

If you prefer setting this up by hand, here are the lines you need in your .zshrc:

zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
autoload -Uz compinit
compinit

The list-colors style tunes colors on file name completions.

Share:
13,141

Related videos on Youtube

chrisjlee
Author by

chrisjlee

@chrisjlee

Updated on September 18, 2022

Comments

  • chrisjlee
    chrisjlee over 1 year

    I use ubuntu 11.04.

    Is there a way to set coloring for output after tab completion listing of a cd, ls, or etc. ?

    i.e.

    myshell@root$ cd ~/user/files/ I hit tab...

    myfile myfoo mybar <-- this output is colored?

    I hope you enjoyed my diagram.

    • Mikel
      Mikel about 12 years
      What exactly should be colored? Do you want files to be colored the same as ls --color would do? Do you want the first one to be colored, then when you press Tab again, the second one to be colored, etc? Something else?
  • xuhdev
    xuhdev about 8 years
    Also see the option visible-stats.
  • user2718606
    user2718606 almost 7 years
    you may have to $if Bash\nset colored-stats on\n$endif to avoid bugs with other programs that don't understand the new readline functions.
  • Andy Carlson
    Andy Carlson about 5 years
    Not working for me on MacOS Mojave 10.14.4. My bash --version is GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0)
  • user2469006
    user2469006 about 5 years
    Works for me. I use github.com/seebi/dircolors-solarized/blob/master/… and just commented out SOCK 35;44 to work better with my light themed terminal.