Operating System - HP-UX
1754392 Members
2721 Online
108813 Solutions
New Discussion юеВ

Change Title on Xterm or dtterm

 
bjs144
Occasional Advisor

Change Title on Xterm or dtterm

Found this cool website, just thoght i'd share it with you.

http://www.shelldorado.com/

My Favorite script changes the title of the dtterm or xterm window with the current pwd! Useful if you have loads of windows minimized!

Thanks www.shelldorado.com, keep up the hard work.


Script below
if [ "$TERM" = xterm ] || [ "$TERM" = dtterm ]; then
alias cd=Xcd
Xcd ()
{
if [ $# -ne 0 ]; then
'cd' "$@"
else
'cd'
fi
NAME="$(uname -n):${PWD}"
# reset name of xterm title bar & icon to $NAME
echo "\033]0;${NAME}\007\c" # set title bar & icon
}
Xcd .
elif [ "$TERM" = hpterm ]; then
alias cd=Hcd
Hcd ()
{
if [ $# -ne 0 ]; then
'cd' "$@"
else
'cd'
fi
NAME="$(uname -n):${PWD}"
LEN=`echo "$NAME\c" | wc -c`
# reset name of hpterm title bar & icon to $NAME
echo "\033&f0k${LEN}D${NAME}\c" # set title bar
echo "\033&f-1k${LEN}D${NAME}\c" # set icon
}
Hcd .
fi


3 REPLIES 3
Richard Ross
Regular Advisor

Re: Change Title on Xterm or dtterm

Guys,

Hoping someone can help explain the following ...

I've been using the following command placed in my .kshrc file to change the title bar within my xterm session:

PS1='^[]0;${HOSTNAME}(${UNAME}): ${PWD}^G$HOSTNAME($UNAME)$PWD> '

Which displays my host, name and working directory in the xterm title bar. This works great on all my servers (aix and hp/ux) except for root on hp/ux 11.11 witch uses /sbin/sh. As I said, this works fine on root on an ll.0 server (/sbin/sh looks to be the same between 11.0 and 11.11 .. which is why I'm confused)

In 11.11 case, when I 'set -o vi' and ESC-K or ESC-J to retrieve my commands, instead of retrieving, the cursor jumps to column one of my prompt. Again, This is only happening with /sbin/sh on root on hp/ux 11.11 servers.

Thanks for any pointers ...
Elmar P. Kolkman
Honored Contributor

Re: Change Title on Xterm or dtterm

The problem is caused by the length of your prompt... The shell tries to calculate where your cursor is on the line of your terminal, but doesn't know that part of your prompt is not displayed on the command line.

What you can do to solve this is put a CTRL-M between the end of the escape sequence and the rest (visible) part of the prompt.

What I did was the following:
PS1=$(settitle `hostname`:'${PWD}')^M`hostname`':${PWD}$ '
(on one line of course, and the ^M is in real life a CTRL-M) and this works. What you then need is a script like the one posted to have it active. Or the simple version I have here:
case $TERM in
xterm|dtterm)
echo "\033]0;$1\007\c"
;;
hp*)
echo "\033&f0k${#1}D$1\c"
;;
*)
;;
esac
Every problem has at least one solution. Only some solutions are harder to find.
Richard Ross
Regular Advisor

Re: Change Title on Xterm or dtterm

Elmar .. THANKS! That was it ...