Project46.Customize the Tcsh Shell


Project 46. Customize the Tcsh Shell

"I liked Project 45, but what if I'm using the Tcsh shell?"

This project gives Tcsh shell alternatives to some of the Bash customization techniques shown in Project 45.

Tcsh customization is effected by setting special shell variables. Simply type a command at the shell prompt or add it to a Tcsh configuration file (see Project 47).

Enhance Command-Line Completion

Tabbed completion in Tcsh works in a similar manner to the way it works in Bash. By default, this feature is enabled, but when faced with an ambiguous completion, it doesn't display possible matches. We can change this behavior by typing (directly in a shell prompt)

% set autolist


From now on, when you type a partial filename and press Tab to complete, Tsch will display possible completions when the filename is ambiguous. You need to press Tab only once.

% ls D<Tab> Desktop/   Documents/ % ls D


To see completion in color, so that different file types appear in different colors, type

% set color


If you object to the annoying Terminal beep generated whenever completion fails, switch off match beeping by typing

% set matchbeep = never


(Terminal's own Window Settings may override Tcsh settings.)

The HFS+ file system used in Mac OS X is not case sensitive, so it makes sense to ignore case during completion. To make do complete to Documents, for example, type

% set complete = enhance


This setting also considers hyphens and underscores to be equivalent.

Tcsh can spot typos in command names and attempt to correct them. Here's an example in which we enable autocorrect and tell Tcsh to correct command names.

% set autocorrect % set correct = cmd


Invoke nano as nuno to see autocorrect in action.

% nuno CORRECT>nano (y|n|e|a)? yes


Type y to accept the correction and launch nano.

Specify argument all instead of cmd, and Tcsh will attempt to correct everything on the command linecommands and filenames too. This feature sounds tempting, but I've found that more often than not, it does something I'd rather it didn't. For example, editing a new file whose name is close to that of an existing file causes Tcsh to attempt filename correction. D'oh!

Change Your Prompt

Tcsh displays the value of shell variable prompt as the main prompt. To change it, simply change prompt.

% set prompt = "Next? "


Tcsh defines several special characters that insert specific information into the prompt. Naturally, we can take advantage of variable expansion in a prompt, too.

Here's a more complex example that uses ANSI codes to control the color of the text written to the screen. You should see a red prompt showing the current directory.

Next? set prompt = "%{\033[31m%}%c3%{\033[0m%} %# " ~/Documents %


The sequence %{...%} marks an ANSI codein this case, \033 (Escape) [31m to set the text color to red and Escape [0m to set it back to black. In the middle, %c3 displays the current working directory up to a maximum of three levels. %# displays the first character listed in shell variable promptchars or the second character when the user is root. The default value of promptchars is

% echo $promptchars %#


Tip

Use command expansion in the prompt. For example, we could display the current date and time by using

% set prompt = "`date` ¬     %# " Wed Jul 13 13:49:29 BST 2005 $



Special-character sequences like %c3 are documented in the Tcsh man page. Search for %/ by typing /%/ in the Tcsh man page, and you should be taken to the start of a section called "prompt."




Mac OS X UNIX 101 Byte-Sized Projects
Mac OS X Unix 101 Byte-Sized Projects
ISBN: 0321374118
EAN: 2147483647
Year: 2003
Pages: 153
Authors: Adrian Mayo

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net