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 "}'
        Makefile
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.

History

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:

!n

This refers to the history event, with index n

!-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

!s

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

!?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.

0

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

n

The nth word

$

The last argument

%

The word matched by an ?s? search

x-y

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).

______________________

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState