44

I am using 'zsh'. In some directory, when I do ls --color=tty. I see some directories have 'blue text' with 'green background', which makes them hard to read.

Can you please tell me how to configure this?

phuclv
  • 27,773
michael
  • 5,945

3 Answers3

47

Assuming you are using GNU ls, you can specify the colors with the environment variable LS_COLORS (note that this is a GNU ls feature and not specific to zsh).

GNU Coreutils has a program called dircolors to help you convert an easy to edit configuration file into a proper (complicated) LS_COLORS variable. See man dircolors for the command, and man dir_colors for the configuration file syntax.

You can

  1. use dircolors --print-database >! dircolors.default to save the defaults (it contains some explanation text) and then modify it.
  2. Google for fancy pre-configured dircolors files (such as this https://github.com/seebi/dircolors-solarized (I've got no relation to this)).

Once done, you'll need dircolors to turn that into a proper LS_COLORS. Note that dircolors outputs in bash and csh formats, for zsh you should use the bash-formatted output.

PS: Use ls --color=auto instead of ls --color=tty.

Francisco
  • 2,298
  • 21
  • 21
  • this is not true for custom colors. LS_COLOR does not work by default on zsh for some reason. See the numerous other posts complaining about this: 1) https://superuser.com/questions/700406/zsh-not-recognizing-ls-colors 2) https://github.com/robbyrussell/oh-my-zsh/issues/5349 – Charlie Parker Nov 12 '19 at 18:50
  • 1
    You're redirecting with >!. What does the exclamation point do? – mazunki Sep 22 '21 at 14:34
  • >! "Same as >, except that the file is truncated to zero length if it exists, regardless of CLOBBER. " https://zsh.sourceforge.io/Doc/Release/Redirection.html – artfulrobot Mar 29 '23 at 08:57
21

The following works for me in zsh 5.7.1 (x86_64-apple-darwin19.0)).

These lines in my .zshrc without any additional incantations configure the colours for ls:

export CLICOLOR=1
export LSCOLORS=ExGxBxDxCxEgEdxbxgxcxd
alias ll="ls -alG"

For the configuration options you can use in LSCOLORS you can simply run man ls and find the section for LSCOLORS. CLICOLOR is explained there as well.

vch
  • 311
1

If you want to disable the blue color and restore the default white color, just uncomment the line "DISABLE_LS_COLORS =" true "in your .zshrc file

Clem
  • 11