iTerm Shell Customizations for bash, zsh and tcsh


Although iTerm works quite nicely out of the box, there are a few unix shell-specific tweaks you can implement that help to take advantage of some of the many nice features. In what follows, I describe and give some examples of a few customizations.


iTerm Tab, Title Bar and $DISPLAY Customizations

I have been using iTerm instead of Apple's Terminal.app for several years. One of the main advantages of this over the Terminal.app that comes with OS X is the tabbed window feature. It has many other features that I also like, including selection to copy text, middle-button-paste, transparency, bookmarks, etc. It is available for free by two inspired authors and regular updates are made available.

The labels on the tabs and title bar can each be customized so that they dynamically display current information about what directory you are in. This frees up valuable screen real estate that an informative but long-winded prompt might consume. In fact, you can have the title bar display one thing, like your full directory path and machine name and anything else you want, and have the tabs display something different, say the last two directories in your path, or what program you are running in the window, or whatever you wish (space on the tab is more limited than on the title bar.)


The method used to achieve this result is different for each of the shells on OS X. For that reason, I've made sample startup scripts that do this for bash, tcsh and zsh users. (If you use ksh, you are on your own. Perhaps it is time to switch to zsh, which is like ksh but much more user-friendly.) These sample startup scripts are linked in the table below.

In addition to the tab and title bar customizations, these sample startup scripts also contain code that sets the $DISPLAY variable if you are an X11.app user. The code is a bit more elaborate than some versions, because it is designed to be compatible with Apple's Fast User Switching. Once the $DISPLAY variable is properly set, you can launch x-windows unix programs from iTerm; there is no need to use xterm to do this.

Click on the links appropriate to your shell in the table below to view or download the relevant sample startup file. Note that there are two links for bash.


Examples of Startup Files Read by Unix Shells
Shell User files Comments
bash .bash_profile or .bashrc only one or the other is read
ksh .profile or .kshrc .kshrc is always read
tcsh .login and .cshrc .cshrc is always read
zsh .zlogin and .zshrc and .zshenv .zshenv is always read; .zshrc almost always read



iTerm -- Finder Interactions

If you want to open an iTerm tabbed session immediately into the same directory displayed in the OS X finder window, or perform the inverse operation (change a Finder window to match the $PWD or a specified directory), you can do so using a collection of unix shell script utilities developed by Gary Kerbaugh. I have made a separate page describing this entitled Terminal-Finder Interactions.

I've also written some man pages for these: posd, cdf, fdc



Additional iTerm Shell Scripts and Functions

I've written a few shell scripts that are handy for iTerm users. To use one of these, download it, make sure it has no suffix, make it executable (chmod a+x scriptname), and put it in your $PATH. (These are written in zsh, but you can run them like this from any unix shell. If you use zsh, you might instead want to put them in your $FPATH).

I've also written several iTerm -- TextMate shell scripts for use specifically with the TextMate editor.
iTerm Shell Scripts
Command name man page Description
cdf cdf cd to the directory of frontmost Finder window
fdc fdc inverse of cdf
posd posd returns the directory path of the frontmost Finder window
cdd cdd changes directory for shell and Finder
cpos cpos copies the path matching that of the frontmost Finder window
posfind posfind run find command in directory of frontmost Finder window
posgrep posgrep run grep command in directory of frontmost Finder window
ntab ntab Open a new iTerm tab and cd to current or specified directory
ntrm ntrm Open a new iTerm terminal session and cd to current or specified directory
tcmd tcmd Open a new iTerm tab and run the specified command
set_title_tab set_title_tab Update iTerm tab and title bar





Click here for web site index Valid HTML 4.01!