[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setting window title in ssh'ed host

From: Gokdeniz Karadag
Subject: Setting window title in ssh'ed host
Date: Sat, 12 Jul 2008 03:10:00 +0300
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20080512 Thunderbird/ Mnenhy/


This is more like a story, I am trying to automatically set "GNU screen window title" equal to the hostname that is connected by ssh.

I am using the following for hardstatus, which presents a list of all open 
hardstatus lastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"

Also my .screenrc connects to some machines,
screen -t hostname
stuff "ssh hostname\015

Sometimes I logout of the connected machine and connect to another.  I don't
want to set title each time I do this.  If there is no screen in the way, the
following bash variable shows the hostname in xterm title.
PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME}\007"'

If I use this, and change %t->%h in hardstatus string, the hostname shows in
the "currently selected window only", but not the others. As there is no
equivalent of "-w" "+w" for xterm title(which is an actual "hard" status), this
path was blocked.

Setting the following in all machines achieves what I want, it sets screen title to hostname,
PROMPT_COMMAND='echo -n -e "\033k${HOSTNAME}\033\\"'
but when I connect to the machine out of screen, It prints the hostname
literally, so the prompt becomes like "hostname address@hidden $ " , which is
ugly and redundant.

To ensure that only ssh sessions within a GNU screen get the "title setter
prompt command", environment variables are useful, I can use the TERM variable,
but in stable debian, the default TERM=screen breaks vim editor, it goes crazy
when you press home, or pageup buttons.  Using TERM=xterm fixes this, so I
cannot check for TERM being equal to "screen".

I put "setenv INSCREEN yes" into .screenrc, and in the target shell, I set
PROMPT_COMMAND if this variable is set, but then,(surprise, surprise!) ssh
would not pass variables to target machine.  At least, does not pass unless you
use AcceptEnv in ssh server config, but I don't want to use it for security
reasons. Ok, maybe not because of security, but changing "ssh server
configuration" for only setting screen's window title seems absurd.

A solution that I imagined was to extend the "stuff" line; it does the ssh
connection, then puts the PROMPT_COMMAND to set GNU screen window title.
escaping this correctly was a chore, but I managed after some experimentation.
stuff "ssh hostname\015export PROMPT_COMMAND='echo -n -e 

But of course, the connections made after these do not set the title. If only
there was a way to set GNU screen window title to the "hard status" set by the
escape sequences in PROMPT_COMMAND of bash ...

[[ rant: Why, why, why this great software gets the most generic name of 
"screen" ?
What's next, "computer", which is a shell that works by reading your mind,
and "earth" which gives the answer to life, the universe, and everything; and does not only say '42' ? So that you search the web for them and find nothing :-/

Please use "GNU screen" all the time, to be search engine friendly,
like I did in this message :-S

/rant ]]

Gokdeniz Karadag

reply via email to

[Prev in Thread] Current Thread [Next in Thread]