Comment Re:So what? (Score 1) 528
I know that. However, it would be more efficient if the "working directory" could be dynamically updated when I (or a script) used the "cd" command.
I don't use a Mac regularly, so I don't know if its terminal handles the right escape codes, I'd be shocked if it didn't. Plain stock xterm has been doing this pretty much forever.
The sequence is ^[]0;string^G
(where ^[ is Escape and ^G is the bell character)
You can use that in your PS1 variable to automatically update the title every time you get a prompt. Or, depending on your shell, you can get fancy with it.
Here's some magic from my
function title() {
a=${(V)1//\%/\%\%}
a=$(print -Pn "%40<...<$a" | tr -d "\n")
case $TERM in
screen)
print -Pn "\e]0;$a @ $2\a"
print -Pn "\ek$a\e\\"
xterm*|rxvt)
print -Pn "\e]0;$a @ $2\a"
esac
}
case $TERM in
screen|xterm*|rxvt)
function precmd() {
title "zsh" "%m(%55<...<%~)"
}
function preexec() {
title "$1" "%m(%35<...<%~)"
}
esac
A little complicated, but it keeps my xterm title set to "command @ hostname(dir)". The %55() is just zsh magic to abbreviate where necessary.
If I'm in a screen session, it also updates the name of the screen window ("tab") to the command.
Here's an excerpt from my
termcapinfo xterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'
defhstatus "screen ^E (^Et) | $USER@^EH"