For the longest time, I depended on .zshrc on the target machine to set the title in my (xterm|iTerm) window title. This has one drawback– if the target host doesn’t have my .zshrc (or support zsh), no title. And this bit me nastily the other day when I did something in the wrong window.
Enter this new .zshrc function, which works by setting the xterm title sequence:
alias ssh="sshWithTitle";
function sshWithTitle(){
local newTitle=$1
print -Pn "\e]0;$newTitle \a"
\ssh $*
}
alias telnet="telnetWithTitle";
function telnetWithTitle(){
local newTitle=$1
print -Pn "\e]0;$newTitle \a"
\telnet $*
} |
Combine this with the following code to set your title to user@host before and after each command and you should always know who you are in a window.
### set title block
HOSTTITLE=${(%):-%n@%m}
TITLE=$HOSTTITLE
# make sure we're in an xterm!
case $TERM in (xterm*|rxvt|screen)
precmd () { print -Pn "\e]0;$TITLE \a" }
preexec () { print -Pn "\e]0;$TITLE \a" }
;;
esac
function title (){
if (( ${#argv} == 0 )); then
TITLE=$HOSTTITLE
return
fi
TITLE=$*
}
#### end set-title-block |
Recent Comments