6
votes

I have enabled dircolors to change the ls command to have yellow for folders when using ls. The problem is that when I use the shell in emacs, it still shows them as navy blue which is hard to read on a black background.

How can I change the colors for the bash shell, or more particularly, the ls command. My color changes work on a opened terminal, but not for emacs. I have emacs23 with X support.

2
I use alias ls="ls -CF" to not depend on colors. M-x eshell works good with colors. - vpit3833
@vpit3833 - I've been using emacs for years but did not know of eshell .. thanks! - David J. Liszewski

2 Answers

10
votes

If you are using ansi-color, it take the colors from the ansi-color-names-vector, the default is:

  ["black" "red" "green" "yellow" "blue" "magenta" "cyan" "white"]

You can customize the colors of the shell output altering the ansi-color-names-vector variable.

Here is mine, work well with zenburn theme.

(setq ansi-color-names-vector
      ["black" "tomato" "PaleGreen2" "gold1"
       "DeepSkyBlue1" "MediumOrchid1" "cyan" "white"])

To see the changes, evaluate the next expresion, and the next out take it in consideration

(setq ansi-color-map (ansi-color-make-color-map))

I hope this helps.

0
votes

Assuming you are using M-x shell

C-h f shell RET says:

If a file ~/.emacs_SHELLNAME' exists, or~/.emacs.d/init_SHELLNAME.sh', it is given as initial input (but this may be lost, due to a timing error, if the shell discards input when it starts up).

So if you export your LS_COLORS environment variable in ~/.emacs.d/init_bash.sh, Emacs should use it.

Edit: hmmm... I'm no longer sure that shell supports this. (I'm having issues with Vista+Cygwin, at any rate!)

You may also like to try out M-x term or M-x ansi-term ?