When using less in OS X, how can I customize the colors with with things are displayed? When I run less within an ansi-term in Emacs the colors don't come out nicely.
$ less --version less 418 Copyright (C) 1984-2007 Mark Nudelman For OSX, this refers to Emacs 22.1.1; Fedora with Emacs 24 has the same behavior.
Emac's ansi-term supports 8 colors. That is all that ANSI specified, and "ansi-term" is named appropriately. The eterm-color terminal description in ncurses is used for this terminal type. Emacs sets TERM to this value (see source):
(defvar term-term-name "eterm-color" "Name to use for TERM. Using \"emacs\" loses, because bash disables editing if $TERM == emacs.") If you override TERM, e.g., to tell applications that it has more colors, then the extra colors will not be used. Likewise, hard-coded applications which ignore the terminal database cannot use extra colors either.
While Emacs can use more than 8 colors in a terminal, ansi-term does not. Reading the source, look for term-ansi-current-color, and see that there is only logic for 30-37, 39, 40-47 and 49:
;; Foreground ((and (>= parameter 30) (<= parameter 37)) (setq term-ansi-current-color (- parameter 29))) ;; Reset foreground ((eq parameter 39) (setq term-ansi-current-color 0)) ;; Background ((and (>= parameter 40) (<= parameter 47)) (setq term-ansi-current-bg-color (- parameter 39))) ;; Reset background ((eq parameter 49) (setq term-ansi-current-bg-color 0)) You may be able to change the palette of colors used by your terminal, but there is no way to make ansi-term differ from that (it will use the first 8 colors even if Emacs can use 256).
Further reading:
For Emacs other than ansi-term:
Also:
I believe it's partially a function of your terminal type, for one.
$ echo $TERM xterm-256color This post might also be worth a look, titled: Piping Ls Through Less With Colors on Mac OS X. Also this setting might prove helpful.
$ export LESS="-erX" -or- $ export LESS="-eRX" You can consult the man page for less to find out more about the various switches above.
-R may be preferable over -r in this case. echo $TERM returns eterm-color). Within a regular terminal, I get xterm-256colorand within tmux I get screen. /etc/DIR_COLORS*. I do not believe there is any central resource where you can control the colors, rather you have to control them per application such as emacs, vim, etc.