I have always been a big desktop, more pixels sort of person. Since GUI desktops became the norm, I’ve always strived for the maximum desktop resolution I could afford, and fit on the desk. And when I’m gifted with the expanse I feel I’m deserved, I invariably fill it with clutter. Vast arrays of overlapping windows, obscuring dozens of dubious desktop icons.
I’m not sure that this approach represents any kind of advantage, although it’s perhaps an insight to the way my mind works; my physical desktop is a direct analogue, in terms of accumulated clutter. It does mean I’m reliant on the window management features of my computer to help me make sense of the mess.
Different software systems offer various techniques for desktop management. I’ve tried most of them. Mac OS X scores fairly well. The menu bar location is consistent with it’s omnipresent
Window
menu.
Command-tab
switches between running applications, Windows-style, and
command-~
does similar things with the active application’s windows. Windows miniaturise themselves to the dock with that amusing ‘genie effect’ scaling, and zoom back up just as easily.
There are flaws, of course. Window resizing is a bit of a pain, and there’s a lot of mousing, on a big desktop the application menu can seem miles away from it’s window, which makes one grateful for keyboard shortcuts. The Dock is a curious and inconsistent thing that doesn’t seem to deserve the prime screen space it demands in order to be even mildly useful
Best of all is the stupidly-named
‘Exposé’
feature. You’ve probably seen it in action, or perhaps one of the legion of kludgy knock-offs for other desktop systems. A flick of the mouse, and the unnavigable cascade of open windows are scaled and zoomed and ordered to fit on your display. Pick one and they all fly back, with your selection promoted to the front position. It’s immensely clever and useful, and quite essential. and quickly became one of those ‘muscle-memory’ things that make you look and feel stupid if you subsequently try to operate a system which doesn’t have it.
Given a large enough desktop area, this method of navigation works well, even for quite large collections of windows. Different applications are recognisable even when reduced to postage-stamp dimensions, and multiple documents like web pages are usually distinguishable by their content, down to similarly modest proportions. Sadly, it all falls down when it comes to terminal emulator windows and this is unfortunate because I tend to always have many of these open at once.
An
old joke
about the
X window system
used to be that it was a very resource intensive way to display two dozen xterm windows at once and a desktop clock. The humour of this may be questionable, but like most mocking jokes, it is built around a truth. The sheer utility of the Unix command line shell in experienced hands is really hard to beat for interactively munging text, and managing files. And munging text and dealing with filing still seems to describe the majority of computer use. Furthermore, the terminal and command shell interface, having evolved from slow serial lines and dialup teletypes, is really efficient for remote use. Working with networked systems, far away or nearby is often best served by popping open a shell and logging in.
Add to this the thirty to forty years of applications that have been built on top of the assumption that the ersatz teletype is the one true way, and it becomes clear why, despite all the developement efforts channeled into fancy-pants ‘Desktop Environment’ GUI software over the last decade, many heavy Unix users inevitably use their GUI as a convenient way of swiching between umpteen concurrent shell sessions in terminal windows. At least I do.
I’m slightly better on the mac, the GUI is so pervasive and coherent, I tend to make more use of the file management tools. But one of the reasons I like the mac is that it’s a nearly-unix underneath all the tinsel, and so the command line still gets plenty of exercise and the terminal windows gather. And they all look frustratingly similar when tiled by exposé.
Colour seemed like an obvious approach. Amongst the many command arguments you can start an xterm with are
-fg
and
-bg
switches. These set the foreground and background colours to one of the named X color resources, respectively. By colouring your terminals differently you get the handy extra visual mnemonic you need to distinguish them when they are shrunken down to tiny tiles. These colours are fixed at launch and harder to type, and make a good candidate for shell aliases. They also don’t apply to terminal emulators that aren’t based on xterm, such as Apple Terminal ones. It would be better if you could set these colours interactively in a way that was portable across terminal types. As I suspected, it turns out you can do exactly this, by inputing special escape sequences.
Using a command like
echo -e "\033[40;1;33m"
you can send control characters to an xterm to set the foreground and background colours of the text. Then, redrawing the screen via ‘clear’ will leave you with a terminal window that has bold yellow text on a black background.
echo -e "\033[42;1;31m"
would give you bold red text on bright green. Easy to spot at any size, and it works in Apple Terminal too!
The breakdown of how this works is as follows. The
-e
argument to echo means that it will use its own escape sequences to interpret non-printing characters. \033 is the octal code for ESC. The string recipe is actually ESC then
[
which intiates the sequence, followed by a list of numeric attribute codes separated by semicolons and then the charcter m. The following table lists some of the ANSI display attribute codes codes that are useful.
| Attribute
|
Description
|
| 1
|
Bold
|
| 2
|
Normal (not bold)
|
| 4
|
Underline
|
| 5
|
Blink
|
| 7
|
Inverse video
|
| 8
|
Invisible
|
| 30
|
Foreground black
|
| 31
|
Foreground red
|
| 32
|
Foreground green
|
| 33
|
Foreground yellow
|
| 34
|
Foreground blue
|
| 35
|
Foreground magenta
|
| 36
|
Foreground cyan
|
| 37
|
Foreground white
|
| 40
|
Background black
|
| 41
|
Background red
|
| 42
|
Background green
|
| 43
|
Background yellow
|
| 44
|
Background blue
|
| 45
|
Background magenta
|
| 46
|
Background cyan
|
| 47
|
Background white
|
Using the table, you can construct escape strings to dynamically change the color of your terminals.
echo -e "\033[32;47m" ; clear
would change your colors scheme to green text on a white background, for example. The drawbacks are obvious. The numbers are hard to remember, and the string is tricky to type. This calls for a
gross hack
! I define three butt-ugly functions in my bash profile that simplify this process greatly. They’re listed below.
function _fg {
case $1 in
y)
FG="1;33"
;;
g)
FG="1;32"
;;
r)
FG="1;31"
;;
p)
FG="1;35"
;;
W|w)
FG="1;37"
;;
b)
FG="1;34"
;;
B)
FG="1;30"
;;
esac
}
function _bg {
case $1 in
y)
BG="43"
;;
g)
BG="42"
;;
r)
BG="41"
;;
p)
BG="45"
;;
W|w)
BG="47"
;;
b)
BG="44"
;;
B)
BG="40"
;;
esac
}
function xtc
{
FB=$1
F=$( echo | cut -c1 )
B=$( echo | cut -c2 )
_fg $F
_bg $B
CMD="\033[${BG};${FG}m"
echo -e $CMD && clear
}
The way this works is I get a short mnemonic comand
xtc
to use for changing the terminal color. I define the colors as single letter constants, in separate helper functions for both foreground and background colours. Then I can just use type
xtc rb
to instantly refresh the terminal I am using to be bold red on blue. I can then use this as a memory-aid, by assigning distinct colours to different terminals as I use them. This makes them easy to pick out when shrunk. A kludge, but a handy one to have about