Abstract
In this article, I will describe some of the main features of TCSH, which I believe makes it worth using as the primary login shell. This article is not meant to persuade bash users to change! I've never used bash, and by that reason I know very little about it.
As some of you surely know, I've created a configuration tool called The Dotfile Generator, which can configure TCSH. I believe that this tool is very handy when one wants to get the most out of TCSH (without reading the manual page a couple of times.) Because of that I'll refer to this tool several times throughout this article to show how it can be used to set up TCSH.
With a high knowledge of your shell's power, you may decrease the time you need to spend in the shell, and increase the time spent on the original tasks
Basically one can complete on files and directories. This means that you can not complete on host names, process id's, options for a given program etc. Another thing you can not do with this type of completion is to complete on directory names only, when typing the argument for the command cd
In TCSH, the completion mechanism is enhanced so that it is possible to tell TCSH which list to complete from for each command. This means that you can tell TCSH to complete from a list of host names when completing on the commands rlogin and ping. An alternative is to tell it to complete only on directories when the command is cd.
To configure user defined completion with The Dotfile Generator (from now on called TDG) go to the page completion -> userdefined, this will bring up a page which looks like this:
As the command name, you tell TDG which command you wish to define a completion for. In this example it is rm. Next you have to tell TDG which arguments to the command, this completion should apply to. To do this, press the button labeled Position definition. This will bring up a page, which is split in two parts:
In the first part, you tell TDG, that the position definition, should be
defined from the index of the argument, which is trying to be completed
(the one, where the tab key is pressed.) Here you can tell it that you
wish to complete on the first argument, all the arguments except the first
one etc.
| |
The alternative to position dependent completion is pattern dependent completion. This means that you can tell TDG, that this completion should only apply if the current word, the previous word or the word before the previous word conform with a given pattern. |
This solution is a bad idea if the list is used several places (e.g. a list of host names) in that case, one should select the list to be located in a variable, and then set this variable in the .tcshrc file.
To set up such a completion, first develop the command, which return 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 saying Output From Command.
Here's a little Perl command, which find the targets in a makefile:
perl -ne 'if (/^([^.#][^:]+):/) {print "$1 "}' MakefileIf this is inserted in the Entry, one can complete on targets from the file called Makefile, in the current working directory.
If someone should think that its only to promote TDG, that I describe TCSH through it, (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`@'
As has been discussed in issue6 of the Gazette, some of the prompt may be located in the xterm title bar instead of on the command line. To do this, choose font change and select Xterm. | |
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 contain the sting s |
With these commands, you can re-execute a command. E.g. just type !!, to re-execute the previous command. This is however often not what you want to do. What you really wants 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 however often see that you very often refer to the previous command, so if no event specifier is given, the previous command is used. This means that instead of writing !!:$, you may only write !$.
More words designators exists, and it's even possible to edit the words with different commands. For more information about this and for more examples, please take a look into the tcsh manual
It is possible to expand the history references on the command line before you evaluate them by pressing ESC-SPC or ESC-! (This is: first the escape key, and next the space key or the ! key). On some keyboards you may use the meta key instead of the escape key. I.e. M-SPC (One keystroke!) | |
* | Match any number of characters |
? | Match a single character |
[...] | Match any single character in the list |
[x-y] | Match any character within the range of characters from x to y |
[^...] | Match elements, which does not match the list |
{...} | This expands to all the words listed. There's no need that they match. |
^... | ^ in the beginning of a pattern negates the pattern. |
An example of this is the program mcopy which copy files from disk. To copy all files, you may wish to use a star as in: mcopy a:* /tmp. This does however not work since the shell will try to expand the star, and since it can not find any files, which starts with a:, it will signal an error. So if you wish to send a star to the program, you have to escape the star: mcopy a:\* .
There exists two very useful key bindings, which can be used with patterns: The first is C-xg, which list all the files matching the pattern, without executing the command. The other is C-x*, which expand the star on the command line. This is especially useful if you e.g. wishes to delete all files ending in .c except important.c, stable.c and another.c. To create a pattern for this, might be very hard, so just use the pattern *.c. Then type C-x*, which will expand *.c to all you .c files. Now it's easy to remove the three files from the list
TCSH has a mechanism to create aliases for commands. This means that you can create an alias for ls -la just called la.
Aliases may refer to the arguments of the command line. This means that you can create a command called pack, which take a directory name and pack the directory with tar and gz. etc. Aliases can often be a bit hard to create since one often wants history/variable references expanded at time of use, and not at the definition time. This has been done easier with TDG, so go to the page aliases, to define aliases. If you end up with an alias you can not define on this page, but in tcsh, please send me an email. For more information about aliases, see the tcsh manual
0.020u 0.040s 0:00.11 54.5% 0+0k 0+0io 21pf+0wInformative? Yes but... The gnu time command is a bit more understandable:
0.01user 0.08system 0:00.32elapsed 28%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+0minor)pagefaults 0swapsBut still...
In TDG you can configure the output from the time command on the page called jobs. It looks like this:
As for the prompt, here's an entry once again for mixed tokens and and ordinary text. Remember, if there is something in TDG that you do not understand, help is available by pressing the right mouse button over the given widget.