I am trying to get screen
to set my xterm
title. I have this working outside of screen
, but screen
keeps whatever title was in place when I started it. Here is my .bashrc
:
function bash_prompt_command() { # How many characters of the $PWD should be kept local pwdmaxlen=25 # Indicate that there has been dir truncation local trunc_symbol=".." local dir=${PWD##*/} pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen )) NEW_PWD=${PWD/#$HOME/\~} local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen )) if [ ${pwdoffset} -gt "0" ] then NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen} NEW_PWD=${trunc_symbol}/${NEW_PWD#*/} fi export NEW_PWD } PROMPT_COMMAND=bash_prompt_command # Color chart @ http://wiki.archlinux.org/index.php/Color_Bash_Prompt case "${TERM}" in "xterm") TITLEBAR='\[\033]0;\u@\h > ${NEW_PWD}\007\]' PS1="${TITLEBAR}\[\e[1;32m\][\e[0;36m\]\u\e[1;32m\]@\e[1;33m\]\h\e[1;32m\]] \e[0;37m\]\${NEW_PWD}/ \e[1;32m\]\$ \[\e[0m" ;; "screen") TITLEBAR='\[\033]0;\u@\h > ${NEW_PWD}\007\]' ESC='\[\ek\e\\\]' PS1="${TITLEBAR}\[\e[1;32m\][\e[0;36m\]\u\e[1;32m\]] \e[0;37m\]\${NEW_PWD}/ \e[1;32m\]\$ ${ESC}\[\e[0m" ;; *) PS1="\[\e[1;32m\][\e[0;36m\]\u\e[1;32m\]@\e[1;33m\]\h\e[1;32m\]] \e[0;37m\]\${NEW_PWD}/ \e[1;32m\]\$ \[\e[0m" ;; esac
And here is my .screenrc
:
hardstatus alwayslastline hardstatus string '%{= kg}[%{Y}%H%{g}][%= %{= kw}%?%-Lw%?%{=b kR}(%{W}%n-%t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]%{g}[%{B}%m.%d.%Y %{G}%c%{g}]' termcapinfo xterm|xterms|xs|rxvt ti@:te@ termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007' altscreen on shelltitle '$ |bash'
What am I doing incorrectly?
Update (19 August 2010):
The problem is that you cannot update the terminal's title from within screen when you set alwayslastline
. So my solution was to just give up and settle for a predetermined, useful, title for my screen sessions. My updated .bashrc
and .screenrc
can be found at http://bitbucket.org/jsumners/rcfiles/src.
Actually, there is a way to send escape sequences directly to the xterm, passing through screen. It was not easy to find, but from the screen code (src/ansi.c) I think its been there since 2005. I have it working in xterm, Gnome Terminal, and putty. I found a note in mintty source indicating it does not work there simply because they don't handle DCS (unless it was fixed recently).
From the documentation for screen below (at http://www.gnu.org/software/screen/manual/html_node/Control-Sequences.html )
The ANSI DCS (Device Control String) is an escape code that is used to send directly to a terminal (I think that was its original purpose from many years ago). Such a string is terminated with an ST escape code (String Terminator).
Wrap the string to set the terminal's window title inside a DCS..ST block, and it goes through screen and updates correctly, even with hardstatus alwayslastline.
DCS = \033P, ST = \033\
Example - to update the window title with the current working directory, use
Better late than never! Hope this helps someone.
Just in case I'm wrong about the screen source changes: I am running the latest from screen-session git, which in turn is using almost the latest from screen git (with some changes specific to screen-session). But the log messages are dated from 2005 screen (you can see the changes made to that commit regarding DCS handling if you clone the screen git repo and use the command below).
The escape codes are different inside screen.
This outside of screen:
is equivalent to this inside screen:
Changing your case ${TERM}="screen" titlebar to
will solve your problem.
crb is kind of right, but
a) the escape code he uses do not work for me. It should be
\033k
instead of\033_
. Seescreen (1)
under"TITLES (naming windows)"
. So it should be:b) this kind of escaping is only used for setting the title of the screen-window. One instance of screen can have multiple windows, each of them has a name, that is what is displayed in
hardstatus
andcaption
with thet
escape sequence.c) the normal bash escaping works if you set the right terminfo for xterm in
.screenrc
:(this also
works on my machine
for putty)So in order to set the right title for both the screen window and the putty/xterm title, I use someting like:
for reference: http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x395.html
I'm not going to answer the question completely, but let me suggest the way of solving the issue. Many window managers support EWMH specification. There is also a command line tool
wmctrl
which is able to interact with them. Using this tool, one may easily change active window's title with the following command:It is also possible to change window icon, layout and other properties.The tool probably will not work for PuTTY since Windows doesn't support EWMH, but most of the Linux systems should accept it.
With this method it doesn't matter whether you use
screen
or not.Last 2 weeks I have searched many forums and I haven't found the answer for the question:
How to get all command output to Putty title?
Needed it for other programs to know when some jobs on a server is done and is it done right or wrong. Plink stdout and stdin wasn't working, I used many tweaks with wait delays and for some commands that worked for others not. XSEL and XCLIP couldn't be installed on that server.
So here is the solution:
On putty client and suse server it looks like this:
Hopefully someone will be able to use this. It won't work for all server types and putty client settings, of course, but the idea should work well.