Using the OpenStep Desktop
この本のみを検索
PDF 文書ファイルをダウンロードする

Using the Terminal Application

17

Although you can run standard UNIX(R) programs and commands on your system, such programs cannot be run directly from the workspace, which does not include traditional UNIX constructs such as standard input and standard output.
To run these programs, you can use the Terminal application. Terminal offers a number of useful features:
  • Scrollers let you scroll backward to text that is no longer displayed in the window.
  • Text can be copied and pasted within a Terminal window, between windows, or to and from other applications that support cutting and pasting, such as Mail and Edit.
  • Terminal has a Print command to enable you to print the contents of a window, and a Find command to let you search for text.
  • Terminal's Services menu enables you to make interapplication requests. You can also define your own Terminal services for use in other applications.
  • Terminal's Preferences command enables you to change the size, title bar text, emulation characteristics, and font properties of one or more Terminal windows.
  • Terminal provides strict VT100 terminal emulation. Every UNIX program or utility you run (such as Emacs or vi) should work as intended.
The rest of this chapter describes Terminal in more detail.

Introduction to Terminal

A UNIX shell is a program that functions as an intermediary between you and the UNIX operating system. As the shell runs, it prompts you for commands, interprets what you type, and passes the commands to the operating system for execution. For more information about the two most common UNIX shells, the Bourne Shell and the C Shell, see their UNIX manual pages (sh(1) and csh(1)).
You start Terminal in the workspace as you would any other OpenStep(TM) application, by double-clicking its icon in the dock or locating it with the File Viewer (in /usr/openstep/Apps) and double-clicking. You can use the Workspace Manager's Preferences command to make Terminal start when OpenStep starts.
Terminal runs in its own window, in which you can type commands and run UNIX programs and scripts. Figure 17-1 shows a typical Terminal window.

グラフィック

Figure 17-1

You can create additional Terminal windows as you need them with the New Shell command. To change a window's characteristics, select the appropriate settings in the Preferences panel as described in "Setting Terminal Preferences" on page 17-3.

Setting Terminal Preferences

The Preferences command in the Info menu displays the Terminal Preferences panel, shown in Figure 17-2. The Preferences panel lets you change values and set new default values for various Terminal options. For example, you can set the font properties of a particular window, or specify different default font properties to be used for new windows. The figures in this section show the settings you start out with the first time you use the Terminal application. As you click in shell windows, the Preferences panel shows the settings for the main window.

グラフィック

Figure 17-2

Type values and click on buttons to specify new preferences. You may need to click on Set Window to set the new preferences (or, click on Set Default to make the new settings be the default settings or Show Default to show the currently defined default settings). New settings remain in effect until you change them. However, some settings affect only new windows while others affect existing Terminal windows as well. Specifically, when no buttons are displayed at the bottom of the panel, settings are global and apply to all Terminal windows.

Note - If you open Terminal Preferences when more than one Terminal window is open, it will display preferences for the current main window (the Terminal window in which you last clicked).

Terminal Preferences are divided into the following seven groups:
  • Window preferences
  • Title Bar preferences
  • VT100 Emulation preferences
  • Display preferences
  • Activity Monitor preferences
  • Shell preferences
  • Startup preferences
Each group of options is displayed in its own view in the Preferences panel. Select the view you want by clicking on the button labeled Window at the top of the panel and dragging.

Window Preferences

You can use the Window Preferences panel to set the size and font of one or more Terminal windows, as shown in Figure 17-3 on page 17-5. If you click on Set Window, the settings are applied to the Terminal window that is currently the main window. If you want the settings to apply to new windows, click on Set Default.

グラフィック

Figure 17-3

The Columns and Rows fields specify values for the number of columns and rows. Even after setting the number of columns and rows, you can still resize the window, thereby changing the number of columns and rows for that window.
The When Shell Exits field lets you specify what you want to have happen to a window when the shell running in it exits. In some special situations, a window might not obey the default setting. For example, double-clicking on a command in the workspace results in a window that stays open even after the command finishes running.
Use the Font field to specify a font for one or more Terminal windows as follows:
  • Click on the Set button to open the Font panel.
  • In the Font panel, select a font (note that only fixed-width fonts are listed) and font size. Click on the Set button in the Font panel to type the settings in the Font field of the Preferences panel.
  • Click on Set Window in the Preferences panel to set the font for just the main window, or click on Set Default to make this font the default for new windows.

Title Bar Preferences

You can use the Title Bar view of the Preferences panel to configure the title bar of one or more Terminal windows, as shown in Figure 17-4. If you click on Set Window, the new settings you specify are applied to the Terminal window that is currently the main window. If you want the settings to apply to new windows you create, click on Set Default.

グラフィック

Figure 17-4

The Include these Elements field provides a number of elements that you can include in the title bar of Terminal windows, including a "custom title" element that you define yourself. Any combination of elements can be used. If no elements are selected, the title that is used is simply Terminal.
To specify a custom title, type it in the Custom Title field. The custom title is used in the title bar, however, only if you click on the Custom Title box in the Include these Elements field.
As you experiment with various combinations of elements, the sample title bar displayed in the Preferences panel is updated to show the effect of the current settings.

VT100 Emulation Preferences

The VT100 Emulation view is used to set the VT100 characteristics of Terminal windows (see Figure 17-5).

グラフィック

Figure 17-5

"Translate new lines to carriage returns when pasting" should normally be checked. It is required by some other operating systems, and it works correctly for most UNIX programs.
If "Generate VT100 codes from the keypad" is checked, the keys on the numeric keypad generate VT100 keypad sequences. Otherwise, the keys on the numeric keypad generate the characters shown on the keys. Holding down the Alt key while pressing a key on the numeric keypad toggles the interpretation temporarily.
If "Perform strict VT100 emulation" is checked, some additional (and normally undesirable) aspects of VT100 emulation are strictly enforced:
  • If you type a Delete character at the left edge of a Terminal window, the command-line cursor will not wrap around to the end of the previous line. This may make it difficult to edit long command lines that wrap.
  • Strict DECCOLM handling is enforced. Otherwise, the DECCOLM escape code to change the window's size is obeyed only if the new size is larger than the old size.
  • The + key on the numeric keypad generates a comma (,) character.
When "Alternate key generates Escape sequences" is selected, typing a character while you hold down the Alt key causes a two-character sequence to be generated--an Escape character followed by the character you typed. (This is useful when running Emacs, so you can use the Alt key as a Meta key.) Click "Alternate key generates special characters" if you want Alt key combinations to generate a single character with the high bit set. Some programs interpret special characters in their own way, so this does not always work as expected; Emacs, for example, simply strips out the high bit from special characters.

Note - If necessary, you can specify a character other than Escape as the first character in a two-character sequence. To do so, use the dwrite shell command to set the value of the Terminal Meta variable to the decimal value of the desired character.

Display Preferences

The Display view of the Preferences panel is used to set various display characteristics of one or more Terminal windows (see Figure 17-6 on page 17-9). If you click on Set Window, the new settings you specify are applied to the Terminal window that is currently the main window. If you want the settings to apply to new windows you create, click on Set Default.

グラフィック

Figure 17-6

If the Enabled box is checked, windows retain text that scrolls off the top of the window in a scrollback buffer, allowing text that is scrolled off the window to be scrolled back into view, copied, or printed. Otherwise, text that scrolls off the top of the window cannot be retrieved.
If you enable the scrollback buffer, you can choose to let it grow without limit or you can specify the maximum number of lines that you want saved. Whichever you choose, you can use the Edit menu's Clear Buffer command at any time to clear the buffer.
Although it is often useful, the scrollback buffer adds to the amount of memory that is used by the Terminal program, and is unnecessary in some Terminal windows (for example, one that is running a text editor such as Emacs rather than a UNIX shell).
If the "Wrap lines that are too long" box is checked, characters that would extend beyond the right edge of the window wrap around to the beginning of the following line. Otherwise, each line of text occupies only one line in the window--the last character that fits on a line is overwritten by subsequent characters that are displayed on that line.
If the "Scroll to the bottom of the window when input is received" box is checked, typing in the Terminal window causes the window to scroll to the end of the buffer and display the insertion point (of course, if the insertion point happens to be already visible and positioned at the end of the buffer, no scrolling occurs). Otherwise, typing never causes the window to scroll automatically.

Activity Monitor Preferences

Normally, Terminal tries to determine whether your Terminal windows are in active use (busy) by monitoring the processes inside them. If Terminal finds something interesting happening inside a window, it marks the window with a broken "X". As with unsaved document windows in other applications, you will be prompted for confirmation before closing a busy window or quitting Terminal when there are busy windows.
To determine whether a window is clean (not busy), Terminal looks at information about processes it considers relevant. For example, Terminal considers shells and a few other processes such as su to be innocuous and, in general, will not mark windows busy on account of them. Occasionally Terminal may be wrong about whether a window is clean.
In the Activity Monitor view of the Preferences panel (see Figure 17-7 on page 17-11), you can designate additional clean command names in the Clean Commands list (likely candidates are rlogin and telnet). Commands you specify in this list are not used in determining whether a window is busy or clean.
Click on the "Activity monitor enabled" button if you want to enable or disable activity monitoring. When activity monitoring is off, Terminal always asks for confirmation before letting you quit.
Click on the "Background processes are 'clean'" button if you want to specify whether background processes are considered relevant in determining whether a window is clean. For example, a window running a background process could be considered clean, as long as the process is running without problems in the background. (The current process or one that you have explicitly suspended with Control-z will always cause the window to be classified as busy.)

グラフィック

Figure 17-7


Note - Terminal cannot respond to processes running on other machines, so you should not rely on Terminal's process monitor when logged into a remote system.

Shell Preferences

The Shell view of the Preferences panel (see Figure 17-8 on page 17-12) is used to specify a shell or other program to be run in Terminal windows.
Use the Shell field to specify the absolute path name of a shell or program to run on startup. Possible values include /bin/csh, /bin/sh, and /usr/ucb/vi.

Note - You must press the Return key after typing the path name in order for the new value to be set.

グラフィック

Figure 17-8

If the "Read login script" box is checked (and you are using csh), Terminal runs your .login file for each new Terminal window you open. Otherwise, the .login file is ignored.

Startup Preferences

The Startup view of the Preferences panel, shown in Figure 17-9 on page 17-13, lets you specify what happens when Terminal starts.
When Terminal starts you can have it do nothing (that is, create no windows), create one new shell window, or open a startup file (that is, a configuration file that specifies a collection of windows to open). If you select "Open the startup file," you need to make sure a startup file is specified in the Startup File portion of the panel.

Note - For information about how to create a startup file, see "Saving a Terminal Configuration for Later Use" on page 17-14."

グラフィック

Figure 17-9

Click on the Auto-Launch check button if you auto-launch the Terminal application and want it to be hidden initially. This button has no effect if you do not auto-launch Terminal.
Although you can have any number of Terminal configuration files in your ~/Library/Terminal directory, you can specify only one as the startup file. To specify a particular Terminal configuration file as the startup file, type its path name in the Path field or click on Set to open an Open panel in which to select the path name.

Note - The path name you type must be an absolute path name beginning with a slash (/); characters such as tilde (~) do not work.

Color Preferences

The Colors view of the Preferences panel, shown in Figure 17-10, lets you choose several options for the appearance of the Terminal windows.

グラフィック

Figure 17-10

Saving a Terminal Configuration for Later Use

Information about a window or set of windows can be saved to a file, enabling you to save your preferred configurations for later use, as shown in Figure 17-11 on page 17-15. Everything about each window is saved except the contents of the scrollback buffer--this includes the shell, the size and location of the window on the screen, the title bar and font characteristics, and whether or not the window is miniaturized. To save a configuration, choose Save (or Save As) in the Shell menu. Terminal appends a .term file extension to the file name you specify. Since Terminal looks for configuration files in your ~/Library/Terminal directory, this is where you should save them.

グラフィック

Figure 17-11

When you first save the configuration (or whenever you choose Save As), you can choose whether you want just the main window or all windows saved to the file.
Once a window is associated with a file, you can use the Save command to flush the settings out again without seeing a Save Panel, just as with other documents. However, if more than one window belongs with that file, all the relevant windows will be resaved (the menu item indicates this by changing to Save Set). This allows you to open your favorite set of files, rearrange the windows, then just choose Save to save them all back into the file. There is no way to select a subset of the currently open windows to go into a new file.
To open a configuration file, choose Open in the Shell menu. To have a configuration file open automatically each time you start Terminal, either check the box in the Save or Save As panel, or specify the file name in the Startup view of the Preferences panel.

Printing the Contents of a Terminal Window

To print all or part of the text in a Terminal window, open the Print panel by choosing Print in the main menu (see Figure 17-12).

グラフィック

Figure 17-12

Finding Text in a Terminal Window

The Find panel lets you search for text in the main Terminal window. To open the Find panel, choose Find Panel in the Find menu (see Figure 17-13 on page 17-17).

グラフィック

Figure 17-13

The Find panel locates the next occurrence of a specified string, and can search either forward or backward. In the Find field, type the string to search for. The controls in the Find panel have the effects shown in Table 17-1.
Table 17-1
ControlEffect
NextSelects the first occurrence of the Find string following the current selection or insertion point. (Pressing the Return key has the same effect, but with one difference: If you have used the keyboard alternative to display the panel, pressing Return causes the panel to disappear instead of remaining on the screen.)
PreviousSelects the first occurrence of the Find string, searching backward from the current selection or insertion point.
Ignore CaseMakes the find operation case-insensitive (that is, capitalization is ignored when determining a match). If this box is unchecked, the search is case-sensitive.
If the end of the text is reached, Find continues searching from the beginning (conversely, when searching backward, if the beginning of the text is reached, Find continues searching from the end).
If no instance of the Find string is located, Terminal beeps and the message "Not Found" is displayed in the Find panel.
Commands in the Find menu (which is in the Edit menu) provide alternatives and shortcuts to using the Find panel. There is also a Jump to Selection command for scrolling the insertion point into view. For more information, see "Terminal Commands" on page A-33.

Defining Services for Use in Other Applications

Although by default Terminal does not make services available to other applications through the Services menu, Terminal does contain a Terminal Services
panel that you can use to define any services you want Terminal to provide.
To open the Terminal Services panel, choose Terminal Services in the Info menu. If no Terminal services are defined, you will see a panel asking if you want to load a set of example services (see Figure 17-14). You may find it useful to load and examine this set of examples, and then remove those you do not want to keep.

グラフィック

Figure 17-14

Currently defined services are listed at the top of the panel. You can add services, as well as redefine or delete existing commands.
  • To add a service, click on the New button. A new entry named New Service #1 is added to the service list. Type the name that you would like to see in the Services menu, and then configure the service using the controls in the Terminal Services panel. When you are finished, click on OK.
  • To delete a service, select it and click on the Remove button.
  • To modify a service definition, select its name and then redefine the service using the controls on the Terminal Services panel. When you are finished, click on OK.
The Accept field lets you specify what type of data the service accepts. Click on one or more of these buttons as appropriate.
The Use Selection field lets you specify whether the selected text should be used as a command-line argument, or as input to the service. Click on one or the other as appropriate.
The Execution field lets you specify various options that affect the running of the service, such as whether the output is returned or discarded.
When defining the service, you can use the tokens %s and %p to refer to the locations where the selection and prompted input are inserted, respectively. Prompted input is not requested unless %p appears in the definition.