Take the 2-minute tour ×

When executing the command shell-command, the output shown in the associated buffer is not colorized.

This is particularly annoying when calling a testing framework (outputting yellow/green/red...) from within emacs.

How can I configure, or extend, emacs in order to have shell-command allowing colorized output in the shell and preserving the colors while representing that output?


ps. I'm using the Bash shell, on a UN*X system.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You can implement your own shell-execute, something like

(defun my-shell-execute(cmd)
   (interactive "sShell command: ")
   (shell (get-buffer-create "my-shell-buf"))
   (process-send-string (get-buffer-process "my-shell-buf") (concat cmd "\n")))
share|improve this answer
nice hack, i did implement it with a little tweak: (concat "reset\n" cmd "\nexit 0 &> /dev/null\n") –  mgodinho Jan 20 '11 at 8:00
add comment

This is probably what you want :

share|improve this answer
had tried that hook before, in combination with (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t), but it seems to only affect the shell-mode and not a simple shell-command. –  mgodinho Jan 20 '11 at 7:14
@mgodinho: Well, the accepted answer is not doing a shell-command is opening a shell-mode (with a renamed buffer) and without this add-hook the accepted answer is not producing any color. at least for me. –  Pablo Marin-Garcia Apr 28 '11 at 13:17
add comment

Your Answer


