4

I'm currently setting my PS1 title with by concatinating three variables in my .bashrc in such a way:

export TERMSERVER=`who am i | awk '{print $NF}' | tr -d ')''('`
if [ -n "$TERMSERVER" ] ; then
  PS1_TITLE='\h ($MACHTYPE) - $SHELL[$SHLVL] <-- $TERMSERVER'
else
  PS1_TITLE='\h ($MACHTYPE) - $SHELL[$SHLVL]'
fi
export PS1="$PS1_TITLE\n$PS1_LINE\n$PS1_PROMPT"

I also open up several PuTTY and launch a different GNU screen in each PuTTY, each with a session name, eg:

screen -T screen -U -S session-1 (in PuTTY #1)
screen -T screen -U -S session-2 (in PuTTY #1)

I'ld love to see session-1 or session-2 appear in my PuTTY window title, but I can't find a correct .screenrc configuration of hardstring working. I also can't find a method to correctly map the contents of "/var/run/screen/S-user" to my current session. I tried using ${PPID}, but it'll fail if in a subshell.

Excerpt from my current .screenrc:

# Every x seconds, requery window title                     
backtick 1 600 600 id -un                                   

# The window's title                                        
hardstatus ignore        
# *** this is the current window title I use since I can't get what I want.
hardstatus string "%1`@%H"                               

caption always                                              
caption string "%{= KW}%-w%{= wk}%50>%n %t%{-}%+w%< %=%H %l"

Is there any method to obtain what I want?

BlakBat
  • 1,279

1 Answers1

2

If you want that screen prints its session name on the PuTTY window title add this function to your .bashrc:

screen ()
{
    sessionname=$(echo $@ | fgrep -- '-S ' | sed 's/.*-S \([^ ]\+\).*/\1/');
    echo -ne "\033]0;${sessionname:-Putty}\007";
    command screen $@;
    echo -ne "\033]0;Putty\007"
}

Run screen as usual.

The function checks for an option called -S , extracts the session name, sets it with terminal escape sequences (or sets Putty if session name is empty) and runs the screen binary. When the screen binary exits, the PuTTY window title is reset to Putty.

Since seeing is believing :-) :

This is a Putty session ready to execute screen. Putty session ready to execute screen.

Inside a screen session. Notice the PuTTY window title. Inside a screen session. Title is screen session name.

Screen session ended. Title is reset. Screen session ended. Title is Putty.

jaume
  • 5,657