Yesterday’s Thoughts

April 29, 2006

Labels in iTerm Tabs

On the Mac, I use iTerm, an open source project, as my Terminal client. I don’t have any strong objection to Terminal, I haven’t really used it enough to tell. iTerm has tabs, I installed it the day I got my Powerbook, and customized to my needs. It has keyboard shortcuts to open terminals on each of the hosts I care about. A good useful tool.

One small annoyance is the labelling of the tabs. By default they are labelled with the name of the host they were opened to. This causes two problems, 1) I can have five tabs open to the same host, so I have to remember which is which and 2) I can connect to a connect to a second host and the tab still shows the original host.

On a whim (I had five tabs labelled “localhost”) I decided to check if there were a new version available that had labelled tabs. There was a newer version, and while there, I found a hint about setting the tabs if your shell was zsh and a link to a page of wgscott’s with similar methods for both zsh and tcsh.

Both those methods involved creating a function that was called whenever the directory was changed. They both contained strings of escape characters that were echoed on each chdir and the effect was to change the text on the tabs.

A simpler solution, that I think would also work in tcsh (I have no zsh experience) is to stuff the escape sequences into the PROMPT string. I did that in bash, adding the following to my .bashrc file.

 export PS1="^[]1;h:W^G$PS1"

where the bits inside the quotes are “ESC” typed with V[ for the first character and “^G” typed with VG. The \h and \W are bashisms specially created for the prompt strings and and the other characters are themselves.

In bash prompts, \h is the hostname, without the domain, and \W is the name of the current directory. There are many other options, see man bash. The environment variable $PS1 is the main prompts. Every time the command shell returns to the prompt, this string is echoed.

Works perfectly. I made this change, synced it to the hosts I use regularly, and no matter how I get there, the tabs labels tell me where I am in that tab.

Technorati Tags: , ,

Post a Comment