Features of the TCSH Shell

LG #35
Output from Command

In many cases the list should be calculated when the completion takes place. For example, a list of users located at a given host or targets in a makefile would need to be calculated.

To set up such a completion, first develop the command which returns the list to complete from. The command must return the completion list on standard output as a space-separated list. When this is done, insert this command in the entry Output From Command.

Here's a little Perl command which finds the targets in a makefile:

perl -ne 'if (/^([^.#][^:]+):/) {print "$1 "}'
If this is inserted in the entry, you can complete on targets from the file
called Makefile in the current working directory.
If someone should think I describe TCSH through it only in order
to promote TDG,(s)he should take a look at the following line, which is the
generated code for the make completion:
complete make  'p@*@`perl -ne \
        '"'"'>if (/^([^.#][^:]+):/) \
        {print "$1"}'"'"'Makefile`@'
Restrict to Pattern

With user-defined completion, you can restrict the files which are matched for each command. Here are two very useful examples:

  • Restrict latex to *.{tex,dtx,ins} The latex command will complete only on files ending in the extensions .tex, .dtx or .ins.

  • Restrict rm to ^*.{tex,html,c,h}.` This means that you cannot complete rm to a .tex, .html, .c or .h file. I've done that a few times, when I wanted to delete a file called important.c~. Since the file important.c existed, TCSH completed only to that name, and... I deleted the wrong file, because I was too quick.

Additional Examples

Additional examples can be obtained by loading the export file distributed with TDG. Please note that if you wish to keep the other pages, you have to tell TDG to import only the page completion/userdefined. This is done on the Details page, which is accessible from the reload page.

Configuring the Prompt

Configuring the prompt is very easy with TDG. Just enter the menu called prompt. On this page you can configure three prompts:

  1. prompt: the usual prompt, which you see on the command line, where you are about to enter a command

  2. prompt2: is used in foreach, and while loops, and at lines continuing lines ended with a slash

  3. prompt3: is used when TCSH tries to help you, when it meets commands it doesn't know—i.e., spell checking

The prompts are mixed with tokens and ordinary text. The tokens are inserted by clicking on them in the menu below the scrollbar, and the ordinary text is simply typed in. When a token is inserted, an indication will be shown in the entry. Figure 4 is an example of how this may look.

Figure 4. Prompt and Text Mix

Some of the prompts may be positioned in the xterm title bar instead of on the command line. To do this, choose font change and select Xterm.


The history mechanism of the shell makes it easier to type similar commands after each other. To see a list of the previously executed commands, type history.

The following table lists the event specifiers:


This refers to the history event, with index n


This refers to the history event which was executed n times ago: !-1 for the previous command, !-2 for the one before the previous command, etc.


This refers to the previous command


This refers to the current command


This refers to the most recent command whose first word begins with the string s


This refers to the most recent command which contains the string s

With these event specifiers, you can re-execute a command, e.g., just type !!, to re-execute the previous command. However, this is often not what you want to do. What you really want is to re-execute some part of a previous command, with some new elements added. To do this, you can use one of the following word designators, which is appended to the event specifier with a colon.


The first word, i.e., the command name


The nth word


The last argument


The word matched by an ?s? search


Argument range from x to y


All the arguments to the command (equal to ^-$)

Now it's possible to get the last argument from the previous command, by typing !!:$. You'll often see that you need to refer to the previous command, so if no event specifier is given, the previous command is used. This means that instead of typing !!:$, you need type only !$.

More word designators exist, and it's even possible to edit the words with different commands. For more information and examples, please take a look at the TCSH manual found on-line at http://www.imada.ou.dk/Technical/Manpages/tcsh/History_substitution.html.

It is possible to expand the history references on the command line before you evaluate them by pressing ESC-SPC or ESC-!. (That is: first the escape key, and next the space bar or the ! key). On some keyboards you may use the meta key instead of the ESC key, i.e., M-SPC (one keystroke).