Thursday, June 14, 2007

man dir_colors ; ls -d --color a.out Desktop |xxd

wjy@ubuntu:~$ ls -d --color a.out Desktop |xxd
0000000: 1b5b 3030 6d1b 5b30 313b 3332 6d61 2e6f .[00m.[01;32ma.o
0000010: 7574 1b5b 3030 6d0a 1b5b 3031 3b33 346d ut.[00m..[01;34m
0000020: 4465 736b 746f 701b 5b30 306d 0a1b 5b6d Desktop.[00m..[m

wjy@ubuntu:~$ echo -e '\e[01;32mfoo bar\e[00m'
foo bar
wjy@ubuntu:~$ python
>>> print '\x1b[01;32mfoo bar\x1b[00m'
foo bar

wjy@ubuntu:~$ man dir_colors
..................

OTHER TERMINAL TYPES (ADVANCED CONFIGURATION)
If you have a color-capable (or otherwise highlighting) terminal (or printer!) which uses a different set of
codes, you can still generate a suitable setup. To do so, you will have to use the LEFTCODE, RIGHTCODE, and END‐
CODE definitions.

When writing out a filename, ls generates the following output sequence: LEFTCODE typecode RIGHTCODE filename END‐
CODE, where the typecode is the color sequence that depends on the type or name of file. If the ENDCODE is unde‐
fined, the sequence LEFTCODE NORMAL RIGHTCODE will be used instead. The purpose of the left- and rightcodes is
merely to reduce the amount of typing necessary (and to hide ugly escape codes away from the user). If they are
not appropriate for your terminal, you can eliminate them by specifying the respective keyword on a line by
itself.

NOTE: If the ENDCODE is defined in the global section of the setup file, it cannot be undefined in a terminal-spe‐
cific section of the file. This means any NORMAL definition will have no effect. A different ENDCODE can, how‐
ever, be specified, which would have the same effect.

NOTES
The default LEFTCODE and RIGHTCODE definitions, which are used by ISO 6429 terminals are:

LEFTCODE \e[
RIGHTCODE m

The default ENDCODE is undefined.

No comments: