How do I get Emacs shell mode to either render (or ignore) my colors instead of printing ASCII codes?

StackOverflow https://stackoverflow.com/questions/256264

  •  05-07-2019
  •  | 
  •  

Question

The symptom of the problem looks like "[0m[27m[24m[J[34;1" which on a terminal translates into the color blue.

-A

Was it helpful?

Solution 2

The solution that is currently giving me some success is to redefine the shell function as an ansi term:

;; shell-mode
(defun sh ()
  (interactive)
  (ansi-term "/bin/zsh"))

OTHER TIPS

I've got the following in my .emacs

(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)

For the "ignore" alternative, put something like "alias ls=ls" or "unset LS_COLORS" in your ~/.emacs_{bash,tsch,whatever-your-shell-is-called} file. This file is executed in all subordinate shells created by emacs.

Emacs sends the new shell the contents of the file ~/.emacs_shellname as input, if it exists, where shellname is the name of the file that the shell was loaded from. For example, if you use bash, the file sent to it is ~/.emacs_bash. If this file is not found, Emacs tries to fallback on ~/.emacs.d/init_shellname.sh.

The following should work in your .bash_profile or .bashrc

case $TERM in
xterm-color)
export PS1='\[\e]0;\W\007\]\[\e[34;1m\]\W\[\e[0m\]\$ '
;;
*)
export PS1='\W\$ '
;;
esac
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top