screen-users
[Top][All Lists]
Advanced

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

Re: How to set screenname automatically to hostname.


From: Brian Kroth
Subject: Re: How to set screenname automatically to hostname.
Date: Mon, 25 Jan 2010 14:27:35 -0600
User-agent: Mutt/1.5.18 (2008-05-17)

I'm sure I've made this comment before, but this thing is worth looking
at if you're using bash, else zsh natively has the ability to do it.
Basically it allows you to run a command just before every command you
run whereas the PROMPT_COMMAND gets run just before it prints a new
prompt (ie: after you've run the command).

http://www.twistedmatrix.com/users/glyph/preexec.bash.txt
http://glyf.livejournal.com/63106.html?thread=210818

I've used some variant of this for a long time and am quite happy with
it.  With it and some other environment variables in place on the
machines you're using (easier if you've got shared remote home dirs of
some sort) you can have the screen title set to whatever long running
program you last executed on the host in question and include some other
information like what machine you're on as which user and what directory
you're in.

The exact output can be customized, but here's an example window list:

1 @tux-63:~ $ vim foo.txt
2 ~ $ vim bar.txt
3 address@hidden:/tmp # 
4 ~ $ ssh somehost

1) Is my user on a different machine running vim of some file.
2) Is my user on the local machine running vim of another file.
3) Is a bash session in /tmp as root on a different machine.
4) Would be an ssh session to some host that doesn't have your
bash.preexec setup on it.  Basically the title stays the same until the
command finishes so it would still be possible to identify the host
you're ssh'd to, though in this case it would only go one level deep
whereas having things setup everywhere means it will always reset your
window title no matter how many machines you ssh through.

As another example here's my current caption line:
1&$ ~ $ mutt  2-!$ ~ $ irssi ...

Now if only I could search the window list on the title :)

Cheers,
Brian

halonothing <address@hidden> 2010-01-23 12:39:
> 
> 
> Jostein Berntsen wrote:
> > 
> > This blog post discusses how to achieve that:
> > 
> > http://platypope.org/blog/2007/3/10/fun-with-screen
> > 
> > - Jostein
> > 
> 
> 
> Almost have it working... The only thing i'm noticing is that when I (Ctrl+a
> c) to make a new screen, it seems to be parsing the hostname of the box
> screen is running on, rather than parsing the hostname of the server I ssh
> to shortly after making the screen. Does that make sense?  In other words,
> all of the screen title names are the name of the local hostname.  I want to
> be able to ssh to another server and have it change my screen title to the
> host I've connected to. Any input? 
> 
>  
> 
> p.s. here's the relevant parts of my screenrc, and my PS1 in .bashrc
> 
> export PS1='address@hidden \w \$ '
> 
> # TERMINAL SETTINGS
> #
> ------------------------------------------------------------------------------
> 
> # The vt100 description does not mention "dl". *sigh*
> termcapinfo vt100 dl=5\E[M
> 
> # turn sending of screen messages to hardstatus off
> hardstatus off
> # Set the hardstatus prop on gui terms to set the titlebar/icon title
> termcapinfo xterm*|rxvt*|kterm*|Eterm* hs:ts=\E]0;:fs=\007:ds=\E]0;\007
> # use this for the hard status string
> #hardstatus string "%h%? users: %u%?"
> shelltitle '@|'
> hardstatus alwayslastline
> hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f
> %t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
> 
> # set these terminals up to be 'optimal' instead of vt100
> termcapinfo xterm*|linux*|rxvt*|Eterm* OP
> 
> # Change the xterm initialization string from is2=\E[!p\E[?3;4l\E[4l\E>
> # (This fixes the "Aborted because of window size change" konsole symptoms
> found
> #  in bug #134198)
> termcapinfo xterm 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l'
> 
> # To get screen to add lines to xterm's scrollback buffer, uncomment the
> # following termcapinfo line which tells xterm to use the normal screen
> buffer
> # (which has scrollback), not the alternate screen buffer.
> #
> #termcapinfo xterm|xterms|xs|rxvt ti@:te@
> 
> #
> ------------------------------------------------------------------------------
> # STARTUP SCREENS
> #
> ------------------------------------------------------------------------------
> 
> # Example of automatically running some programs in windows on screen
> startup.
> #
> #   The following will open top in the first window, an ssh session to
> monkey
> #   in the next window, and then open mutt and tail in windows 8 and 9
> #   respectively.
> #
> # caption always "%?%F%{-b bc}%:%{-b bb}%?%C|%D|%M %d|%H%?%F%{+u wb}%?
> %L=%-Lw%45>%{+b by}%n%f*%t%{-}%+Lw%-0<"
> # caption always "%?%F%{-b kr}%:%{-b rr}%?%C|%D|%M %d|%H%?%F%{+u wk}%?
> %L=%-Lw%45>%{+b wr}%n%f*%t%{-}%+Lw%-0<"
> 
> 
> -- 
> View this message in context: 
> http://old.nabble.com/How-to-set-screenname-automatically-to-hostname.-tp27026674p27289702.html
> Sent from the Gnu - Screen mailing list archive at Nabble.com.
> 
> 
> 
> _______________________________________________
> screen-users mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/screen-users

Attachment: signature.asc
Description: Digital signature


reply via email to

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