Team LiB
Previous Section Next Section

Hack 50. Stop Using Terminal Command-Line Switches

Power users switch window managers almost as often as "Alias" character Sydney Bristow changes hairstyles. Here's a way to deal with the fact that each window manager starts up X terminals differently.

GNOME and KDE are terrific in terms of ease of use, and their terminals (gnome-terminal, konsole) make it easy to save your preferences. But when you want to do something that sucks up computer resources (such as a large compile), you can free up resources by using a more minimalist window manager, such as Fluxbox, WindowMaker, ION, or any of several dozen others that are available. Also, some people who like to use a graphical desktop simply prefer these lightweight window managers, because they run better on older hardware.

If you're going to use a minimalist window manager to conserve system resources, it doesn't make much sense to use the fancier terminals available for GNOME and KDE, which might need to load a lot of libraries just to run. If the point of using a minimalist window manager is to save resources, it makes sense to use a lean terminal emulator, such as xterm, aterm, or rxvt. This hack shows you how to start up any of these terminal programs without having to use command-line switches to make them appear the way you want them to.

Here's a scenario that involves the hard way to make a terminal such as xterm launch with your favorite settings in different window managers. You want to give Fluxbox a try, so you fire it up as your window manager. You launch an xterm from the menu, and up it comes with the default settings. And for you, the default settings are wrong, wrong, wrong. So, what do you do? You create a ~/.fluxbox directory, find the default menu file (a file appropriately named menu, usually found in /usr/share/fluxbox), copy it to your ~/.fluxbox directory, and start customizing the commands that launch terminals. For example, if you want to start an xterm with a predefined size, a white foreground, a black background, a font size of 10x20, the ability to remember 4,000 lines after they've scrolled off, etc., you have to create a menu entry that reads something like this:

[exec] (xterm) {xterm -fn 10x20 -fg white -bg black -geometry 120x40
-sb 4000}

Now, what happens when you have set up all your terminal menu options for Fluxbox, and then you decide you prefer to use WindowMaker? You can't just insert a copy of the preceding line of code into the file WindowMaker uses to construct its menus, because WindowMaker uses a different format for menu command entries.

Fear not. There is an oft-forgotten file in which you can set your preferences once, and then just start xterm with the simple xterm command and no arguments, and aterm with the aterm command and no arguments, and these terminals will pop up just the way you want them to. It even simplifies menu entries. Here's all you need for the Fluxbox entry:

[exec] (xterm) {xterm}

The crucial file is located in your home directory, and it is called .Xdefaults (some distributions prefer to use .Xresources, but all distributions seem to check and respect .Xdefaults). Few programs these days care about the settings in ~/.Xdefaults, but most of the lean, mean terminal programs still use it.

Here is a sample ~/.Xdefaults file that customizes the look and feel of xterm, aterm, and rxvt with the same settings used earlier in the Fluxbox menu file to define an xterm, and even more. All three terminals tend to respect the following XTerm definitions (or at least the definitions for which aterm and rxvt have equivalent features), but sometimes you might need to define some separate settings for aterm, rxvt, and other terminals.

XTerm*scrollBar: on
XTerm*rightScrollBar: on
XTerm*title: XTerm
XTerm*font: 10x20
XTerm*savelines: 4000
Xterm*geometry: 120x40
XTerm*background: black
XTerm*foreground: white
XTerm*colorMode:  on
XTerm*dynamicColors:  on
XTerm*underLine:  off
XTerm*colorBDMode: on
XTerm*colorBD: cyan
XTerm*colorULMode:  on
XTerm*colorUL: magenta
XTerm*customization: -color
XTerm*reverseWrap: true
XTerm*color0: #000000
XTerm*color1: #b21818
XTerm*color2: #18b218
XTerm*color3: #BE5F00
XTerm*color4: #6D85BA
XTerm*color5: #b218b2
XTerm*color6: #18b2b2
XTerm*color7: #b2b2b2
XTerm*color8: #686868
XTerm*color9: #FF5454
XTerm*color10: #54FF54
XTerm*color11: #FFFF54
XTerm*color12: #73A5FF
XTerm*color13: #FF54FF
XTerm*color14: #54FFFF
XTerm*color15: #FFFFFF

More options are available for each terminal program mentioned. The best way to find out which options you can control is to view the manpage for each terminal and view the section entitled RESOURCES. As this method of controlling the look and feel of programs is going out of style, some of these resources are not very well documented. You might have to play around with various settings until you get the look you like best.

    Team LiB
    Previous Section Next Section