< Day Day Up > |
To customize the shell used by the Terminal, start by changing the Terminal's Preferences (Terminal Preferences). In the Preferences pane, you can tell the Terminal to execute the default shell or a specific command (such as an alternative shell) at startup.[*] You can change the default shell in the Terminal preferences, but it will not affect the login shell used for remote or console logins. Changing a user's default shell is covered later in this chapter. You can also adjust the Terminal's characteristics using Terminal Window Settings (or -I), which brings up the Terminal Inspector, shown in Figure 1-3. Table 1-1 lists the available window settings . Changing these settings affects only the topmost Terminal window. If you want to change the default settings for all future Terminal windows, click the Use Settings As Defaults button at the bottom of the Terminal Inspector window. Figure 1-3. The Terminal Inspector
One useful option available in the Emulation tab is "Option click to position cursor". If you enable this feature, you will be able to Option-click with the mouse to position the cursor in Terminal applications such as vim or Emacs (this could save you many keystrokes when you need to move the insertion point). This option also works over a remote login session, assuming that this is supported by the remote host's terminal capabilities. 1.4.1. Customizing the Terminal on the FlyYou can customize the Terminal in shell scripts using escape sequences or AppleScript commands. xterm users may be familiar with the following command to set the xterm window's title when using the bash shell: echo -n -e "\033]0;My-Window-Title\007" or the equivalent when using tcsh: echo '^[]2;My-Window-Title^G' Mac OS X's Terminal accepts these sequences as well.
To type the ^[ characters in bash, use the key sequence Control-V, Escape (press Control-V and release, then press the Escape key). To type ^G, use Control-V, Control-G. The vim editor supports the same key sequence; Emacs uses Control-Q instead of Control-V. You can capture the bash escape sequence in a function that you can include in your .bash_profile script: function set_title ( ) { case $TERM in *term | xterm-color | rxvt | vt100 | gnome* ) echo -n -e "\033]0;$*\007" ;; *) ;; esac } Then you can change the title by issuing the following command: set_title your fancy title here You may want to package this as a shell script and make it available to everyone who uses your system, as shown in Example 1-3. Example 1-3. Setting the Terminal title in a shell script#!/bin/bash # # Script settitle # Usage: settitle title # if [ $# == 0 ]; then echo "Usage: settitle title" else echo -n -e "\033]0;$*\007" fi You can also use osascript to execute AppleScript commands that accomplish the same thing: osascript -e \ 'tell app "Terminal" to set custom title of first window to "Title"' 1.4.2. Working with File and Directory NamesTraditionally, Unix users tend to avoid spaces in file and directory names , sometimes by inserting hyphens and underscores where spaces are implied, as follows: textFile.txt text-file.txt text_file.txt However, most Mac users tend to insert spaces into file and directory names and, in a lot of cases, these names tend to be long and descriptive. While this practice is okay if you're going to work in the GUI all the time, it creates a small hurdle to jump over when you're working on the command line. To get around these spaces, you have two choices: escape them, or quote the file or directory name. To escape a space on the command line, simply insert a backslash (\) before the space. This also works with other special characters, such as a parenthesis. Because they have meaning to the shell, special characters that must be escaped are: * # " " ' \ $ | & ? ; ~ ( ) < > ! ^. Here is an example of how to use a backslash to escape a space character in a file or directory name: cd ~/Documents/My\ Shell\ Scripts Or you can use quotation marks around the file or directory name that contains the space, as follows: cd ~/Documents/"My Shell Scripts" There is one other way to get around this problem, but it involves using the Finder in combination with the Terminal application. To launch a Classic (Mac OS 9 and earlier) application such as Word 2001, which probably lives on the Mac OS 9 partition of your hard drive, you could enter the path as follows, using escape characters: open -a /Volumes/Mac\ OS\ 9/Applications\ \(Mac\ OS\ 9\)/Microsoft\ Office\ 2001/Microsoft\ Word Or you can enter the path using quotes: open -a /Volumes/"Mac OS 9"/"Applications (Mac OS 9)"/"Microsoft Office 2001"/"Microsoft Word" As you can see, neither way is very pretty, and both require you to know a lot of detail about the path. Now for the easy way:
You can also drag and drop URLs from a web browser. For example, to use curl to download files from the command line:
1.4.2.1. Tab completionIf you want to type a long pathname, you can cut down on the number of keystrokes needed to type it by using tab completion . For example, to type /Library/StartupItems, you could type /Li<Tab>, which gives you /Library/. Next, type S<Tab>. This time, instead of completing the path, you're given a choice of completions: Screen Savers, Scripts, and StartupItems. Type a little bit more of the desired item, followed by a tab, as in t<Tab>. The full key sequence for /Library/StartupItems is /Li<Tab>St<Tab>. If you have multiple completions where a space is involved, you can type a literal space with \<Space>. So, to get a completion for /System Folder (the Mac OS 9 system folder), you should use /Sy<Tab>\ <Space><Tab>. It stops just before the space because /System (Mac OS X's System folder) is a valid completion for the first three characters. 1.4.3. Changing Your ShellAlthough other shells are available in Mac OS X, as we noted earlier, the default shell in Mac OS X Tiger is bash. Earlier versions of Mac OS X shipped with tcsh as the default shell. Although you can change the default shell in the Terminal preferences, this does not affect the login shell used for remote or console logins. To change your default shell in a more pervasive manner, see "Modifying a User" in Chapter 5. If you install additional shells on the system, you'll need to add them to the /etc/shells file to make Mac OS X aware that they are legitimate shells. |
< Day Day Up > |