You are not logged in.

#1 2009-10-12 16:30:49

scv5
Member
Registered: 2008-10-19
Posts: 109

Gnu Screen theme cycle with keybinding

A guy at work did this and shared with me, so i thought I'd continue spreadin the love.    If you have multiple gnu screen sessions going at once, wouldn't it be nice to visually tell them apart without spending time to read the session name of each or trying to see what was going on within each?   

The best way would be to color code the caption and hardlinestatus lines and be able to easily select a "color" per screen session and that's what he and I did.  Using C-g, we/you can easily cycle through various "themes".   This could also be useful if you wanted to cycle through mutiple hardstatus lines that displayed different information too if that's the route you'd like to go.   Anyways here it goes:

#terminfo and termcap for nice 256 color terminal
# allow bold colors - necessary for some reason
attrcolor b ".I"
# tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
# erase background with current bg color
defbce "on"

startup_message off

bindkey ^G screen screen_theme.sh

caption always "%{= KW}%-w%{= gW}%n %t%{-}%+w %-="

hardstatus alwayslastline "%{= kW} %-= %{= kG}Session:%u%{= kW} %5` | %{= kG}Host:%{= kW} %H | %{= kG} MEM:%{= kW} %2`MB |%{= kG} SW: %{= kW}%3`MB | %{= kG}Unread: %{= kW} %4` | %m/%d %C %A"

vbell off

#Backticks to display information in status bar
backtick 1 60 60 $HOME/bin/get_uptime
backtick 2 60 60 $HOME/bin/get_freemem
backtick 3 60 60 $HOME/bin/get_freeswap
backtick 4 60 60 $HOME/bin/get_gmail
backtick 5 60 60 $HOME/bin/get_sessionname

       
defscrollback 5000
screen -t root 0 sudo -s
screen -t shell 1 bash
screen -t shell 2 bash
screen -t shell 3 bash 
screen -t shell 4 bash
screen -t shell 5 bash   
screen -t shell 6  bash 
screen -t shell 7  bash 
screen -M  -t irc 8 irssi
screen -t home 9 ssh home
select 1

This script resides in ~/bin which is in my path.  screen_theme.sh:

#!/bin/bash

INDEXFILE="$HOME/bin/themes/theme_index"

# if this is the first time then set
# the index to 0

if [[ ! -e $INDEXFILE ]]
then
  echo 0 > $INDEXFILE
fi

THEMENO=`cat $INDEXFILE`

THEMEMAX=5

if [[ $THEMENO -eq $THEMEMAX ]]
then
  THEMENO=0
else
  THEMENO=`expr $THEMENO + 1`
fi

echo $THEMENO > $INDEXFILE

THEMEFILE=$HOME/bin/themes/theme${THEMENO}

if [[ -e $THEMEFILE ]]
then
  bash $THEMEFILE $STY
else

  # reset the index back to zero if broken

  echo 0 > $INDEXFILE
fi

then I created a directory ~/bin/themes.  Within that directory I have the following files:

$ ls themes/
theme0  theme1  theme2  theme3  theme4  theme5  theme_index

Each theme file is another color theme, the index just holds a count of the number of themes.

An example of theme0  ( remember when doing yours to escape your backticks, otherwise it'll break).

#!/bin/bash

# yellow

SESSION=$1

screen -S $SESSION -X caption always "%{= KW}%-w%{= yk}%n %t%{-}%+w %-="
screen -S $SESSION -X hardstatus alwayslastline "%{= kW} %-= %{= ky}Session: %u%{= kW}%5\` | %{= ky}Host:%{= kW} %H | %{= ky} MEM:%{= kW} %2\`MB |%{= ky} SW: %{= kW}%3\`MB | %{= ky}Unread: %{= kW}%4\` | %m/%d %c"

Here's how my screen started:
http://tuxtraining.com/images/screen1.png

After C-g
http://tuxtraining.com/images/screen2.png

After C-g again
http://tuxtraining.com/images/screen3.png

and so on.

Last edited by scv5 (2009-10-12 16:38:51)

Offline

#2 2009-10-12 16:55:15

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Gnu Screen theme cycle with keybinding

Rather nice idea, but useless for most of us as we only use one screen session normally. There is a screenrc thread on the forums (http://bbs.archlinux.org/viewtopic.php?id=55618&p=3), you may want to add this there too smile


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#3 2009-10-12 17:23:49

scv5
Member
Registered: 2008-10-19
Posts: 109

Re: Gnu Screen theme cycle with keybinding

It's nice if you stay logged in to 50+ servers at a time, organize each into type of servers or city they're located in, etc.. 

Not really for desktop usage it all you're looking for is screen to support your mpd/irssi/mutt/rtorrent type stuff

Offline

#4 2009-10-13 14:19:14

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Gnu Screen theme cycle with keybinding

Lich wrote:

... useless for most of us as we only use one screen session normally.

How do you know this?

Offline

#5 2009-10-13 14:54:09

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Gnu Screen theme cycle with keybinding

scv5 wrote:

It's nice if you stay logged in to 50+ servers at a time, organize each into type of servers or city they're located in, etc..

Not really for desktop usage it all you're looking for is screen to support your mpd/irssi/mutt/rtorrent type stuff

I do have a login on many servers.  Your idea is interesting and you've given me something to think about, thanks.  Here is how I currently handle logging into many servers.  I create a screenrc file for every server for any unique screen settings:

$ cat $HOME/.screen/screenrc.$HOSTNAME
    source $HOME/.screenrc

    screen -t 'dm'      6
    screen -t 'weechat' 7 sh -c "weechat-curses && /bin/bash"
    screen -t 'mutt'    8 sh -c "mutt && /bin/bash"
    screen -t 'torrent' 9 sh -c "rtorrent && /bin/bash"

    select 1

** NOTE - one could add their unique colouring for the caption and
hardstatus line here.


I use this script to connect to a machine:

$ cat $HOME/bin/go
    #!/bin/bash

    if [[ -e $HOME/.screen/screenrc.$@ ]] ; then
        ssh -t $@ "LANG=en_CA.utf8 screen -c $HOME/.screen/screenrc.$@ -xRR $@"
    else
        ssh -t $@ "LANG=en_CA.utf8 screen -xRR $@"
    fi

In a local terminal outside of screen I type 'go HOSTNAME'.  When I want
to go to another machine I press 'C-A d' and 'go HOSTNAME'.

Again thanks for sharing, it's appreciated.

Offline

#6 2009-10-13 14:56:15

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Gnu Screen theme cycle with keybinding

steve___ wrote:
Lich wrote:

... useless for most of us as we only use one screen session normally.

How do you know this?

Oh good, we have one of you, this certaintly proves me wrong smile


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#7 2009-10-13 15:10:03

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: Gnu Screen theme cycle with keybinding

steve___ wrote:
Lich wrote:

... useless for most of us as we only use one screen session normally.

How do you know this?

Just a guess, but doesn't that sort of defeat the purpose of a multiplexer?  I mean it's like running 20 instances of firefox instead of using a single firefox window with 20 tabs.  I'm sure some folks prefer the former, but I think it's safe to say the majority use the latter method.


thayer williams ~ cinderwick.ca

Offline

#8 2009-10-13 15:56:45

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Gnu Screen theme cycle with keybinding

thayer wrote:
steve___ wrote:
Lich wrote:

... useless for most of us as we only use one screen session normally.

How do you know this?

Just a guess, but doesn't that sort of defeat the purpose of a multiplexer?  I mean it's like running 20 instances of firefox instead of using a single firefox window with 20 tabs.  I'm sure some folks prefer the former, but I think it's safe to say the majority use the latter method.

I apologize, my question was ambiguous.  I meant "how do you know this
information is useless?".

doesn't that sort of defeat the purpose of a multiplexer?

Do you mean how he is using sessions for 'theming' or the session option in general?

Offline

#9 2009-10-13 16:52:12

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Gnu Screen theme cycle with keybinding

steve___ wrote:
thayer wrote:
steve___ wrote:

How do you know this?

Just a guess, but doesn't that sort of defeat the purpose of a multiplexer?  I mean it's like running 20 instances of firefox instead of using a single firefox window with 20 tabs.  I'm sure some folks prefer the former, but I think it's safe to say the majority use the latter method.

I apologize, my question was ambiguous.  I meant "how do you know this
information is useless?".

I said it's useless for most of us because we use only one screen session, maybe 1 out of 100(?!) users have sessions open on more than one server, I say that makes us a majority. So yeah, it IS useless (for most of us). Let's not hijack this thread with childish arguments. You quoted me in a kind of negative manner, even though I am right, so just email me future rants so I can ignore this in peace. kthxbai


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#10 2009-10-13 23:56:23

scv5
Member
Registered: 2008-10-19
Posts: 109

Re: Gnu Screen theme cycle with keybinding

thayer wrote:
steve___ wrote:
Lich wrote:

... useless for most of us as we only use one screen session normally.

How do you know this?

Just a guess, but doesn't that sort of defeat the purpose of a multiplexer?  I mean it's like running 20 instances of firefox instead of using a single firefox window with 20 tabs.  I'm sure some folks prefer the former, but I think it's safe to say the majority use the latter method.

Sort of, I find screen becomes difficult to manage once we're talking more than the original 0-9 windows and you have to C-a-##, there's also the issue of screenspace.  With firefox i can list my tabs vertically giving me a lot more room to manage my tabs, screen doesn't have that option, so they go horizontally.    If i name all my tabs after the IP or name of the machine theiy are logged into, approach 15-20 windows really creaps on the screenspace.

So typically what i do is have four shells open (grouped together or done in something like terminotor, or tabbed in flux or pekwm) each with 0-9 shells a piece, each session organized into type of servers.   So the upper left may be the email systems i support, the uppser right screen session may hold all the shell of our public facing web environment, bottom left is my local box, bottom right being misc boxes (dns servers, nis/ldap servers, various developement boxes..)  you get the hint.

take into consideration i get one of these going per monitor that gives me approximately 80 shells, which is quite unmanagable in one screen session if you ask me.

Offline

#11 2009-10-14 05:17:05

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Gnu Screen theme cycle with keybinding

I've known quite a few sysadmins in my days. I have never seen any of them with more than...like...4-5 terminals open. May I ask what do you do for a living? Because 80 terminals sounds simply...insane...


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#12 2009-10-15 15:28:24

scv5
Member
Registered: 2008-10-19
Posts: 109

Re: Gnu Screen theme cycle with keybinding

I'm a sys admin for an isp, I support a good number of systems that provide a number of  services for our customers (email, dns, web hosting, dialup, our public facing webservers, a few for internal web apps, a couple of database servers, an ESX environment with about 200-300 guests on it, a NIS server, several FTP servers, an a whole mess of machines responsible for a number of function for our television over IP service. . 

I like to stay logged into most of our important boxes, so if and when i get an alert or someone pops by my desk, i'm ready to work on the issue, whatever the case may be.  Getting to the appropriate box (via organized workspaces, organized terminals and screen sessions) normally takes 1-2 seconds at best because switching to them at this point is in muscle memory.   

I stay logged into them for weeks/months at a time usually.

Offline

Board footer

Powered by FluxBB