home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Caldera Network Desktop 1.0
/
caldera-network-desktop-1.0.bin
/
doc
/
HOWTO
/
mini
/
Colour-ls
< prev
next >
Wrap
Text File
|
1995-05-07
|
6KB
|
180 lines
$Id: MINI-colour,v 1.4 1994/12/05 19:10:26 ravn Exp $
Thorbjoern Ravn Andersen
ravn@imada.ou.dk
A standard installation of Linux with Slackware [*] enables colours with
the 'ls' command. Sometimes you wish to use other colours than the
default, but this is hard to do with a non-black background. This
mini-howto explains which standard escape codes to use and where to use
them.
[* The information in here was compiled with the 2.0.2 release of
Slackware, and the 1.1.54 kernel. It works both with agetty and mgetty_ps.]
1) How to select colours?
Essentially you have two choices:
Method 1: Use the setterm program which is fine if you just need a quick
change. The helpscreen and man page are cryptic, so here you are somewhat
on your own. [If somebody has an adequate description I would love to read
it].
Selections are done like
"setterm -foreground black -background white -store"
where the "-store" makes it the default for the current console. This
needs to be done for each virtual console you want to change, so a good
place might be in your .login file. Now you know as much as I do about
setterm. :-)
Metod 2: Linux uses ANSI escape codes of the form
ESC [ <parameters> m
where ESC is ASCII 27 and <parameters> are zero or more numbers separated
with semi-colons. Valid examples might be
"\033[41;33;1m" which results in bright yellow on red,
"\033[30;47m" which results in white on black, and
"\033[m" which restores the default colour set.
These examples requires that the shell in question recognizes the \xxx
construction. If not, just insert an escape character directly in the
string. In bash/vi type Ctrl-V ESC, and in tcsh/emacs type Ctrl-Q ESC.
2) What colour combinations are available?
This c-shell script shows all colour combinations on the current console:
------------------- CUT HERE-----------
#!/bin/csh
#
# Display ANSI colours. /ravn 941129
#
set esc="\033["
foreach fore (30 31 32 33 34 35 36 37)
set line1="$fore " line2=" "
foreach back (40 41 42 43 44 45 46 47)
set line1="${line1}${esc}${back};${fore}m Normal ${esc}0m"
set line2="${line2}${esc}${back};${fore};1m ${back} Bold ${esc}0m"
end
echo "$line1\n$line2"
end
------------------- CUT HERE-----------
The foreground colour number is listed to the left, and the background
number in the box. If you want bold you add a "1" to the parameters. Put
semi colons in between, and plug it in the <parameters> part above.
Note: The background cannot be bold, so you cannot have yellow (bold brown)
as a background.
3) How to make 'ls' select colours.
The colourised 'ls' command looks for the configuration in
"~/.dir_colors", and failing that in "/etc/DIR_COLORS". It contains a lot
of entries like
LINK 36;1 # symbolic link
FIFO 40;33 # pipe
SOCK 41;01;35 # socket
BLK 41;33;01 # block device driver
CHR 41;33;01 # character device driver
# This is for files with execute permission:
EXEC 32;1
which is exactly the <parameters> part from the ANSI sequence.
Alter these as you wish. See the result with '/sbin', '/etc', and '/dev'.
4) How to set a default colour set.
This is set individually for each virtual console, with the ANSI sequence
[**]
ESC [ 8 ]
which sets the default to the current fore- and background colours. Then
the Reset Attributes string (ESC [ m) selects these colours instead of
white on black.
[** This information was found by browsing the kernel source. I don't know
whether this is standard.]
The method described below is primarily intended for stand-alone systems,
in the sense that logins *only* happen on the console. There should not be
any logins from terminals, modems or other machines, as they may not
understand the sequences added.
On a *stand-alone* Linux system a good file is "/etc/issue", so edit this file directly and check the result by typing
Ctrl-D to a login prompt. If you have a standard Slackware installation
this file is rewritten each time the system is rebooted, so if your
"/etc/rc.d/rc.S" contains lines looking like (around line 75)
# Setup the /etc/issue and /etc/motd to reflect the current kernel level:
# THESE WIPE ANY CHANGES YOU MAKE TO /ETC/ISSUE AND /ETC/MOTD WITH EACH
# BOOT. COMMENT THEM OUT IF YOU WANT TO MAKE CUSTOM VERSIONS.
echo ""> /etc/issue
echo Welcome to Linux `/bin/uname -a | /bin/cut -d\ -f3`. >> /etc/issue
echo >> /etc/issue
you may want to either comment these out or replace the first echo line with
...
# BOOT. COMMENT THEM OUT IF YOU WANT TO MAKE CUSTOM VERSIONS.
ESCAPE="<replace with a single escape character here>"
echo "${ESCAPE}[H${ESCAPE}[37;44m${ESCAPE}[8]${ESCAPE}[2J"> /etc/issue
...
My startup-shell doesn't understand the "\033" so I must insert the ASCII
code 27 literally in my script where indicated (as described in section 1).
The line should then look like 'ESCAPE="^[" '.
This code will home the cursor, set the colour (here white on blue), save
this selection and clean the rest of the screen. This modification takes
effect after the next reboot.
If your Linux box *is not* stand-alone, you may have problems with remote
users since their terminal probably cannot understand the sequences inserted
above.
Then you must make this user-based by adding it to your
.profile (sh/bash)
if [ "$TERM" = "console" ]; then
echo "\033[37;44m\033[8]"
fi
.login (csh/tcsh)
if ( "$TERM" == "console" ) then
echo "\033[37;44m\033[8]"
endif
or system wide by modifying "/etc/profile" or "/etc/csh.login" as root.
(Again, replace \033 with literate escapes if the shell cannot parse \xxx
constructions)
6) Comments and criticism
This is still a rough draft, and English isn't my primary language.
Please feel free to correct me on the above text in order to make it as
clear and correct as possible. This goes, of course, for the information
provided as well.
Comments and criticism goes to
--
Thorbjo/rn Ravn Andersen "...and...Tubular Bells!"
ravn@imada.ou.dk
<http://www.imada.ou.dk/~ravn>