Working with the Command Line


This section covers word completion, editing the command line, and correcting spelling.

Word Completion

The TC Shell completes filenames, commands, and variable names on the command line when you prompt it to do so. The generic term used to refer to all these features under tcsh is word completion.

Filename Completion

The TC Shell can complete a filename after you specify a unique prefix. Filename completion is similar to filename generation, but the goal of filename completion is to select a single file. Together they make it practical to use long, descriptive filenames.

To use filename completion when you are entering a filename on the command line, type enough of the name to identify the file in the directory uniquely and press TAB; tcsh fills in the name and adds a SPACE, leaving the cursor so you can enter additional arguments or press RETURN. In the following example, the user types the command cat trig1A and presses TAB; the system fills in the rest of the filename that begins with trig1A:

tcsh $ cat trig1A  TAB  cat trig1A.302488  


If two or more filenames match the prefix that you have typed, tcsh cannot complete the filename without obtaining more information from you. The shell attempts to maximize the length of the prefix by adding characters, if possible, and then beeps to signify that additional input is needed to resolve the ambiguity:

tcsh $ ls h* help.hist help.trig01 help.txt tcsh $ cat h  TAB  cat help. You can fill in enough characters to resolve the ambiguity and then press TAB again. Alternatively, you can press CONTROL-D to cause tcsh to display a list of matching filenames:

tcsh $ cat help.  CONTROL-D help.hist help.trig01 help.txt tcsh $ cat help. 


After displaying the filenames tcsh redraws the command line so you can disambiguate the filename (and press TAB again) or finish typing the filename manually.

Tilde Completion

The TC Shell parses a tilde (~) appearing as the first character of a word and attempts to expand it to a username when you enter a TAB:

tcsh $ cd ~al  TAB  cd ~alex/  RETURN tcsh $ pwd /Users/alex 


By appending a slash (/), tcsh indicates that the completed word is a directory. The slash also makes it easy to continue specifying the pathname.

Command and Variable Completion

You can use the same mechanism that you use to list and complete filenames with command and variable names. Unless you give a full pathname, the shell uses the variable path in an attempt to complete a command name. The choices listed are likely to be located in different directories.

tcsh $ up  TAB  CONTROL-D update                 update_prebinding_core update_prebinding      uptime tcsh $ up  t  TAB  uptime   RETURN  9:59am up 31 days, 15:11, 7 users, load averages: 0.03, 0.02, 0.00 


If you set the autolist variable as in the following example, the shell lists choices automatically when you invoke completion by pressing TAB. You do not have to press CONTROL-D.

tcsh $ set autolist tcsh $ up  TAB  t  TAB  uptime   RETURN  10:01am up 31 days, 15:14, 7 users, load averages: 0.20, 0.06, 0.02 


If you set autolist to ambiguous, the shell lists the choices when you press TAB only if the word you enter is the longest prefix of a set of commands. Otherwise, pressing TAB causes the shell to add one or more characters to the word until it is the longest prefix; pressing TAB again then lists the choices:

tcsh $ set autolist=ambiguous tcsh $ echo $h  TAB   i  TAB  echo $hist  TAB histfile history tcsh $ echo $hist  o  TAB  echo $history   RETURN 1000 


The shell must rely on the context of the word within the input line to determine whether it is a filename, a username, a command, or a variable name. The first word on an input line is assumed to be a command name; if a word begins with the special character $, it is viewed as a variable name; and so on. In the following example, the second which command does not work properly: The context of the word up makes it look like the beginning of a filename rather than the beginning of a command. The TC Shell supplies which with an argument of updates (a nonexecutable file) and which displays an error message:

tcsh $ ls up* updates tcsh $ which uptime /usr/bin/uptime tcsh $ which up  TAB  which updates updates: Command not found. 


Editing the Command Line

bindkey

The tcsh command line editing feature is similar to that available under bash. You can use either emacs mode commands (default) or vi(m) mode commands. Change to vi(m) mode commands by using bindkey v and to emacs mode commands by using bindkey e. The ARROW keys are bound to the obvious motion commands in both modes, so you can move back and forth (up and down) through your history list as well as left and right on the current command line.

Without pan argument, the bindkey builtin displays the current mappings between editor commands and the key sequences you can enter at the keyboard:

tcsh $ bindkey Standard key bindings "^@"        ->  set-mark-command "^A"        ->  beginning-of-line "^B"        ->  backward-char "^C"        ->  tty-sigintr "^D"        ->  delete-char-or-list-or-eof "^E"        ->  end-of-line ... Alternative key bindings Multi-character bindings "^[[A"      ->  up-history "^[[B"      ->  down-history "^[[C"      ->  forward-char "^[[D"      ->  backward-char "^[[H"      ->  beginning-of-line "^[[F"      ->  end-of-line ... Arrow key bindings down             ->  down-history up               ->  up-history left             ->  backward-char right            ->  forward-char home             ->  beginning-of-line end              ->  end-of-line 


The ^ indicates a CONTROL character (^B = CONTROL-B). The ^[indicates a META or ALT character; you press and hold the META or OPTION key while you press the key for the next character. If this substitution does not work or if the keyboard you are using does not have a META or OPTION key, press and release the ESCAPE key and then press the key for the next character. If the OPTION key does not work while you are using the Terminal utility, see the tip "Activating the META key" on page 31. For ^[[F you would press META-[ or ALT-[ followed by the F key or else ESCAPE[ F). The down/up/left/right indicate ARROW keys, and home/end indicate the HOME and END keys on the numeric keypad.

The preceding example shows the output from bindkey with the user in emacs mode. Change to vi(m) mode (bindkey v) and give another bindkey command to display the vi(m) key bindings. You can pipe the output of bindkey through less to make it easier to read the list.

Correcting Spelling

You can have tcsh attempt to correct the spelling of command names, filenames, and variables (but only using emacs-style key bindings). Spelling correction can take place only at two times: before and after you press RETURN.

Before You Press RETURN

For tcsh to correct a word or line before you press RETURN, you must indicate that you want it to do so. The two functions for this purpose are spell-line and spell-word:

$ bindkey | grep spell "^[$"        -> spell-line "^[S"        -> spell-word "^[s"        -> spell-word 


The output from bindkey shows that spell-line is bound to META-$ (ALT-$ or ESCAPE $) and spell-word is bound to META-S and META-s (ALT-s or ESCAPE s and ALT-S or ESCAPE S). To correct the spelling of the word to the left of the cursor, enter META-s. Entering META-$ invokes the spell-line function, which attempts to correct all words on a command line:

tcsh $ ls bigfile.gz tcsh $ gunzipp  META-s  gunzip  META-s  gunzip bigfile.gz tcsh $ gunzip bigfele.gz  META-$  gunzip bigfile.gz tcsh $ ecno $usfr  META-$  echo $user 


After You Press RETURN

The variable named correct controls what tcsh attempts to correct or complete after you press RETURN and before it passes the command line to the command being called. If you do not set correct, tcsh will not correct anything:

tcsh $ unset correct tcsh $ ls morning morning tcsh $ ecno $usfr morbing usfr: Undefined variable. 


The shell reports the error in the variable name and not the command name because it expands variables before it executes the command (page 341). When you give a bad command name without any arguments, the shell reports on the bad command name.

Set correct to cmd to correct only commands; all to correct commands, variables, and filenames; or complete to complete commands:

tcsh $ set correct = cmd tcsh $ ecno $usfr morbing CORRECT>echo $usfr morbing (y|n|e|a)? y usfr: Undefined variable. tcsh $ set correct = all tcsh $ ecno $usfr morbing CORRECT>echo $user morning (y|n|e|a)? y alex morning 


With correct set to cmd, tcsh corrects the command name from ecno to echo. With correct set to all, tcsh corrects both the command name and the variable. It would also correct a filename if one was present on the command line.

Automatic spell checking displays a special prompt that lets you enter y to accept the modified command line, n to reject it, e to edit it, or a to abort the command. Refer to "prompt3" on page 360 for a discussion of the special prompt used in spelling correction.

In the next example, after setting the correct variable the user mistypes the name of the ls command; tcsh then prompts for a correct command name. Because the command that tcsh has offered as a replacement is not ls, the user chooses to edit the command line. The shell leaves the cursor following the command so the user can correct the mistake:

tcsh $ set correct=cmd tcsh $ lx -l  RETURN e tcsh $ lx -l 


If you assign the value complete to the variable correct, tcsh attempts command name completion in the same manner as filename completion (page 348). In the following example, after setting correct to complete the user enters the command up. The shell responds with Ambiguous command because several commands start with these two letters but differ in the third letter. The shell then redisplays the command line. The user could press TAB at this point to get a list of commands that start with up but decides to enter t and press RETURN. The shell completes the command because these three letters uniquely identify the uptime utility:

tcsh $ set correct = complete tcsh $ upRETURN Ambiguous command tcsh $ up  tRETURN  uptime  4:45pm up 5 days, 9:54, 5 users, load averages: 1.62, 0.83, 0.33 





A Practical Guide to UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

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