4

I have run M-x ansi-color-for-comint-mode-on.

Also, when I use /bin/ls --color=always (or /bin/ls --color=auto) in a regular terminal, I do see colors in the output.

It's only within Emacs' shell-mode that these commands fail to produced colorized output. (The variable LS_COLORS is set to the empty string in all cases.)

Strangely enough, grep --color=always does produce colorized output, even in shell-mode. The echoed commands are are also colorized.

screenshot

(NB: in the illustration above I passed the options -1aF --color=always to /bin/ls, but I get the same "monochrome" output with no flags, or with any combination of flags, and with any argument for the --color option.)

Is there anything else I need to do to get /bin/ls to produce colorized output in shell-mode?


config

;; ~/.emacs

(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(require 'comint)
(set-face-attribute 'comint-highlight-prompt nil
                    :inherit nil)
# ~/.zshrc
LS_COLORS='';
export LS_COLORS

PS1=$'%# '
7
  • The doc string for ansi-color-for-comint-mode says, "In order for this to have any effect, ansi-color-process-output must be in comint-output-filter-functions". Is it, for you? (It is, for me -- I have (ansi-color-process-output comint-postoutput-scroll-to-bottom comint-watch-for-password-prompt) -- and I get ls colors.) Oct 18, 2015 at 17:02
  • Hmm maybe that's N/A, because it's already showing colors for you -- just not for ls. Oct 18, 2015 at 17:05
  • @GregHendershott: Thanks for your comment. I just checked, and my settings for that variable are identical to yours.
    – kjo
    Oct 18, 2015 at 17:14
  • Emacs 25.0.50.1 here and ls produces colored output when run in shell-mode, what version are you using?
    – wvxvw
    Oct 18, 2015 at 17:41
  • 1
    My Emacs (GNU Emacs 24.5.1) sets TERM=dumb in startup.el and my ls from GNU coreutils 8.24 checks TERM even with --color=always. dumb is not a terminal type recognized by dircolors (the utility used by ls to decide how to color the output), so running TERM=ansi ls --color=always in a *shell* buffer works as expected, while ls --color=always does not. So, I would recommend creating an alias similar to alias lls="TERM=ansi gls --color=always". Oct 18, 2015 at 19:59

1 Answer 1

7

My Emacs (GNU Emacs 24.5.1) sets TERM=dumb in startup.el and my ls from GNU coreutils 8.24 checks TERM even with --color=always. dumb is not a terminal type recognized by dircolors (the utility used by ls to decide how to color the output), so running TERM=ansi ls --color=always in a *shell* buffer works as expected, while ls --color=always does not.

So, I would recommend creating an alias similar to

alias ls="TERM=ansi ls --color=always"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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