I'm trying to get ansi colors from my bash process, but I can't get this to work.

(setq shell-process-name "shell-process-name")
(setq shell-process-buffer "*shell-process-buffer*")

(defun open-shell-process ()
  (let ((buf shell-process-buffer)
        (coding-system-for-read 'binary)
        (default-directory "~/"))
    (start-process shell-process-name
    (let ((proc (get-buffer-process buf)))
      (set-process-filter proc 'shell-process-filter)
      (accept-process-output proc 0.1))
    (with-current-buffer buf

(defun shell-process-filter (proc output)
  (let ((buf (process-buffer proc)))
    (with-current-buffer buf
      (goto-char (point-max))
      (insert (ansi-color-apply output)))))

Do I need to change process-environment or what am I missing here ?

  • 1
    Yup, I'd certainly try putting something other than TERM=dumb into process-environment when starting this process.
    – wvxvw
    Dec 5, 2017 at 11:01
  • 1
    I have TERM=xterm-256color and that works with emacs -Q; M-x shell. Reviewing this comment, you really need to provide basics like emacs version, OS, and the commands you are running (M-x shell? M-x term?).
    – Realraptor
    Dec 5, 2017 at 11:45
  • @wvxvw Thanks. It works, but ansi-color-apply seems to be broken. @Realraptor I don't want to change the emacs shells.
    – bertfred
    Dec 5, 2017 at 13:08
  • 1
    ansi-color-apply doesn't work here because it applies text properties to the string. This is correct for strings, but when the string is inserted into the buffer, font-locking overrides the face properties.
    – npostavs
    Sep 8, 2018 at 1:54
  • This seems to be a good alternative github.com/atomontage/xterm-color
    – bertfred
    Sep 8, 2018 at 10:54

1 Answer 1


Extending Realraptor's comment with the answer here: .bash_profile or .bashrc for shell in emacs?

Stick TERM=xterm-256color into your .bashrc, and for good measure, this in .emacs:

(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(add-to-list 'comint-output-filter-functions 'ansi-color-process-output)
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)

Your Answer

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

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