Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Set the title of the Terminal window with cd' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Set the title of the Terminal window with cd
Authored by: boredzo on May 04, '06 10:13:02AM

There's also preexec, which is run before running any command in the shell. I use preexec to add the process arguments to my title bar, and precmd to take them out (by resetting to just the CWD and TTY).

From my .zshenv:

if [[ ( "$TERM" = "xterm-color" ) || ( "$TERM" = "xterm-256color" ) ]]; then
	#When a program starts, put it in the title bar.
	preexec () {
		print -n "\e]0;"; print -Pn "$1 @ %~ @ tty%l\a" | python ~/Python/newlineescape.py
	}
	#When a program exits, remove it from the title bar.
	precmd () {print -Pn "\e]0;%~ @ tty%l\a"}
fi

The Python script newlineescape.py takes out control characters in the arguments that could mess up my title bar and terminal and cause beeping (anything after the first line will be printed to stdout). It's pretty simple:

import sys
sys.stdout.write(' '.join(sys.stdin.read().split()))



[ Reply to This | # ]