screen-users
[Top][All Lists]
Advanced

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

Re: rename each screen according to hostname


From: Trent W. Buck
Subject: Re: rename each screen according to hostname
Date: Wed, 28 May 2008 14:08:55 +1000
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

On Tue, May 27, 2008 at 06:54:10PM -0700, Micah Cowan wrote:
> Trent W. Buck wrote:
> > On Tue, May 27, 2008 at 10:57:59AM +0100, Stephane Chazelas wrote:
> >> On Tue, May 27, 2008 at 07:51:58PM +1000, Chris Henderson wrote:
> >>> I ssh to a lot of servers and every time I have to do C-a A to rename
> >>> the screen session to the hostname I ssh to. Is there anyway screen
> >>> can automatically change the name to the host I am connected to?
> >> [...]
> >>
> >> ssh() { screen -X title "address@hidden"; command ssh "$@"; }
> > 
> > I think the OP wants to change the session name, not the screen
> > (window) title.
> 
> Well, the OP explicitly mentioned C-a A...

Ah, so he did.  Withdrawn.

Regarding answering the original post, I run a screen session on each
host, such that remote screens are nested.  Screen is started
automatically by my login script, .profile.  Lines 46 through 52 set
the parent screen session's window title to the unqualified hostname.

.bash_profile users can omit line 49, as bash always sets $HOSTNAME.

The "type" builtin (lines 48  isn't POSIX, but is widely supported.

This obviously doesn't affect non-login ssh sessions, such as "ssh -t
mail mutt".  I think I prefer it that way.

    34  ## The naive "chsh -s /usr/bin/screen" breaks scp (and other things).
    35  ## Have sh start screen automatically "when appropriate".  That is,
    36  ## 1) not in a screen window (STY);
    37  ## 2) stdin is a tty;
    38  ## 3) screen is installed; and
    39  ## 4) terminal is capable of displaying screen.
    40  ## Replace "$STY" with "$STY$SSH_CLIENT$SSH_ORIGINAL_COMMAND" to avoid
    41  ## nesting screens when sshing (untested).
    42  test -z "$STY" -a -t 0 &&
    43  { type screen && tput clear && tput cup && ! tput hc && ! tput os
    44  } 2>/dev/null >&2 &&          # ignore boring, expected error messages
    45  {
    46      ## Set the window title to the host name.
    47      ## Note that using echo -e \e for ^[ is not portable.
    48      type uname >/dev/null 2>&1 &&
    49      test -n "${HOSTNAME:=`uname -n`}" &&
    50      case "$TERM" in
    51          screen*) printf %bk%s%b%b \\033 "${HOSTNAME%%.*}" \\033 \\0134;;
    52      esac
    53      ## If new session, start agents.
    54      screen -ls | grep -i 'No Sockets found' >/dev/null 2>&1 &&
    55      eval "$(twb-agents)"
    56      ## Start screen.
    57      exec screen -DRR
    58  }





reply via email to

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