Display current jobs in Terminal titles

Feb 07, '02 09:34:00AM

Contributed by: hysterion

This is a follow-up to cft's earlier tip which showed how to put the current working directory in a terminal window's title. Another nice possibility is to display instead the current job. For instance, right now I have six terminal windows with these titles (quite a bit more informative than ttyp1 thru ttyp6...):

The titles appear alphabetically in Terminal.app's "Window" menu, and are also attached to minimized windows in the dock.

The way to do this is explained in Ric Lister's Xterm-Title Howto and is easy to summarize. First, issue the last command above ("vi ~/Lib...") to create and edit a file named 'aliases.mine' in the appropriate directory. This standard location is defined in /usr/share/init/tcsh/README. Next, type "i" and insert this line:
sched +0:00 alias postcmd 'echo -n "^[]0;\!#^G"'
As in the earlier tip, ^[ and ^G here are not to be typed literally. They are the ESC and BEL escape sequences, obtained in vi by typing ctrl-V ctrl-[ for the first one and ctrl-V ctrl-G for the second. Finally, save and close the file (esc :wq! return), open a new terminal window, and marvel.

Addendum to original story: Based on the long series of comments below, here is a version of the command to use which will not cause errors and seems to work in all situations:
sched +0:00 alias postcmd 'echo -n "^[]0; `hostname|cut -d.[space]
-f1`: `echo \\!# | cut -b 1-25`^G"'
Please note it is shown on two lines, but is really one long line. Replace [space] with an actual space character and enter as one line of text.

Second addendum: From the original author, here's a newer version that actually works in all situations (even the above one causes some errors in certain circumstances):

sched +0:00 alias postcmd 'printf "\033]0; %s \007" "\!#:q"'
I have tested this new version, and it works just fine in tcsh...

Comments (30)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020207093427440