Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Screen versions: - Screen version 4.00.03 (FAU) 23-Oct-06 - Screen version 4.00.03jw4 (FAU) 2-May-06 –  BlakBat Oct 30 '12 at 12:37
    
Did you try asking in a the Ubuntu forums? It seems more like something those gurus would know about. –  ppumkin Oct 30 '12 at 12:38
    
@ppumkin: The machines are CentOs and Debian. Anyway, I prefer asking on StackOverflow than on an Ubuntu forum; Ubuntu users probably lurk here too ;-) –  BlakBat Oct 30 '12 at 12:41
    
Well yea even if its centos or wahteverOS-- It still core Linux - And no; some clever guys from Ubuntu SE Linux do not venture this side because they are dedicated for support in Ubuntu(Linux) only. –  ppumkin Oct 30 '12 at 12:48

1 Answer 1

up vote 2 down vote accepted
+100

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.