Basically like some of my own that I've posted below. I'm looking for added functionality to the programme 'screen'. At the very least have a look at the last line for a fantastic 'menu bar' at the bottom of a screen session.

## gyaresu's .screenrc 2008-03-25

# Don't display the copyright page
startup_message off

# tab-completion flash in heading bar
vbell off

# keep scrollback n lines
defscrollback 1000

# Doesn't fix scrollback problem on xterm because if you scroll back
# all you see is the other terminals history.
# termcapinfo xterm|xterms|xs|rxvt ti@:te@

# These will let you use 
bind -c selectHighs 0 select 10 #these three commands are 
bind -c selectHighs 1 select 11 #added to the command-class
bind -c selectHighs 2 select 12 #selectHighs
bind -c selectHighs 3 select 13
bind -c selectHighs 4 select 14
bind -c selectHighs 5 select 15

bind - command -c selectHighs   #bind the hyphen to 
                                #command-class selectHighs 

screen -t rtorrent  0   rtorrent    
#screen -t tunes        1   ncmpc --host= --port=6600 #was for connecting to MPD music server.
screen -t stuff     1
screen -t irssi     2   irssi
screen -t dancing   4       
screen -t python    5   python
screen -t giantfriend   6
screen -t computerrescue    7
screen -t BMon      8   bmon -p eth0
screen -t htop      9   htop
screen -t hellanzb  10  hellanzb
screen -t watching  3   
#screen -t interactive.fiction  8
#screen -t hellahella   8   paster serve --daemon  /home/gyaresu/downloads/hellahella/hella.ini 

shelltitle "$ |bash"

#change the hardstatus settings to give an window list at the bottom of the                                                                        
##screen, with the time and date and with the current window highlighted                                                                            
hardstatus             alwayslastline                                                                                                                          
#hardstatus string '%{= mK}%-Lw%{= KW}%50>%n%f* %t%{= mK}%+Lw%< %{= kG}%-=%D %d %M %Y %c:%s%{-}'
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'

locked by Michael Hampton Dec 13 '13 at 20:03

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

12 Answers 12

up vote 22 down vote accepted

For those wanting a less cryptic way of getting a nice screen set up, I can heartily recommend byobu (formerly called screen profiles). It gives you a nice default set of stuff at the bottom of the screen - the bottom line contains various handy status information, and the second from bottom line contains a list of your screen windows. All this can be configured in a nice easy ncurses menu by pressing F9.

The function keys are mapped to common operations:

  • F2 - create a new window
  • F3 - Go to the prev window
  • F4 - Go to the next window
  • F5 - Reload profile
  • F6 - Detach from the session
  • F7 - Enter scrollback mode
  • F8 - View all keybindings
  • F9 - Configure screen-profiles
  • F12 - Lock this terminal

See this article for a tutorial and screenshots.

Byobu is in the ubuntu repositories from karmic (9.10) onwards. In jaunty it was called screen-profiles. Before that it can be installed from this ppa of from this download page. It's widely packaged for other up-to-date distros aswell.

It does depend on python, but once you have byobu set up as you like it, you can have it generate a tar ball containing all you need to recreate your screen on another computer using byobu-export.

  • Screen-profiles is awesome. I was going to answer with the same. – jtimberman Jun 10 '09 at 18:36

I also use a fairly involved caption/hardstatus line combination, to simulate the effect of dropdown tabs (the caption line is solid grey and the current tab in the hardstatus is the same color).

I also have my shell tell screen what the current process name is and what directory I'm in, so my tab names stay up to date with what I'm doing in each tab. This is critical to remembering what I'm doing where without having to flick through all my open tabs.

 # don't use the hardstatus line for system messages, use reverse video instead
 # (we'll be using it for the list of tab windows - see hardstatus alwayslastline
 # below)
 hardstatus off

 # use the caption line for the computer name, load, hstatus (as set by zsh), & time
 # the caption line gets repeated for each window being displayed (using :split),
 # so we'll use color cues to differentiate the caption of the current, active
 # window, and the others.
 #    always                  - display the caption continuously.  Since
 #                              hardstatus is 'alwayslastline', it will be on the
 #                              next to last line.
 #    "%?%F"                  - if (leading '%?') this region has focus ('%F') 
 #                              (e.g. it's the only region being displayed, or,
 #                              if in split-screen mode, it's the currently active
 #                              region)
 #      "%{= Kk}"               - set the colorscheme to blac[k] on grey (bright blac[K]),
 #                                with no other effects (standout, underline, etc.)
 #    "%:"                    - otherwise ('%:' between a pair of '%?'s)
 #      "%{=u kR}"              - set the colorscheme to [R]ed on blac[k], and
 #                                underline it, but no other effects (bold, standout, etc.) 
 #    "%?"                    - end if (trailing '%?')
 #    "  %h "                 - print two spaces, tthne the [h]ardstatus of the
 #                              current tab window (as set by zsh - see zshrc) and
 #                              then another space.
 #    "%-024="                - either pad (with spaces) or truncate the previous
 #                              text so that the rest of the caption string starts
 #                              24 characters ('024') from the right ('-') edge of
 #                              the caption line.
 #                              NOTE: omitting the '0' before the '24' would pad
 #                              or truncate the text so it would be 24% from the
 #                              right.
 #    "%{+b}                  - add ('+') [b]old to the current text effects, but
 #                              don't change the current colors.
 #    " %C:%s%a %D %d %M %Y"  - print the [C]urrent time, a colon, the [s]econds,
 #                              whether it's [a]m or pm, the [D]ay name, the [d]ay
 #                              of the month, the [M]onth, and the [Y]ear.
 #                              (this takes up 24 characters, so the previous
 #                              pad/truncate command makes sure the clock doesn't
 #                              get pushed off of the caption line)
 #    "%{= dd}"               - revert to the [d]efault background and [d]efault
 #                              foreground colors, respectively, with no ('= ')
 #                              other effects.
 #  other things that might be useful later are
 #    " %H"                   - print a space, then the [H]ostname.
 #    "(%{.K}%l%{-}):"        - print a '(', then change the text color to grey
 #                              (aka bright blac[K]), and print the current system
 #                              [l]oad.  Then revert to the previous colorscheme
 #                              ('%{-}') and print a close ')' and a colon.
 #                              NOTE: the load is only updated when some other
 #                              portion of the caption string needs to be changed
 #                              (like the seconds in the clock, or if there were a
 #                              backtick command)
 #    "%0`"                   - put the output of a backtick command in the line
 #    "%-024<"                - don't pad, just truncate if the string is past 24
 #                              characters from the right edge
 #    "%-="                   - pad (with spaces) the previous text text so that
 #                              the rest of the caption string is justified
 #                              against the right edge of the screen.
 #                              NOTE: doesn't appear to truncate previous text.
 caption always           "%?%F%{= Kk}%:%{=u kR}%?  %h %-024=%{+b} %C%a %D %d %M %Y%{= db}"
 # use the hardstatus line for the window list
 #    alwayslastline      - always display the hardstatus as the last line of the
 #                          terminal
 #    "%{= kR} %-Lw"      - change to a blac[k] background with bright [R]ed text,
 #                          and print all the tab [w]indow numbers and titles in
 #                          the [L]ong format (ie with flags) upto ('-') the
 #                          current tab window
 #    "%{=b Kk} %n%f %t " - change to grey (bright blac[K]) background with
 #                          [b]old blac[k] text, with no other effects, and print
 #                          the [n]umber of the current tab window, any [f]lags it
 #                          might have, and the [t]itle of the current tab window
 #                          (as set by zsh - see zshrc).
 #                          NOTE: the color match with the caption line makes it
 #                          appear as if a 'tab' is dropping down from the caption
 #                          line, highlighting the number & title of the current
 #                          tab window.  Nifty, ain't it)
 #    "%{-}%+Lw "         - revert to the previous color scheme (red on black)
 #                          and print all the tab [w]indow numbers and titles in
 #                          the [L]ong format (ie with flags) after ('+') the
 #                          current tab window.
 #    "%=%{= dd}"         - pad all the way to the right (since there is no text
 #                          that follows this) and revert to the [d]efault
 #                          background and [d]efault foreground colors, with no
 #                          ('= ') other effects.
 hardstatus alwayslastline "%{= kR} %-Lw%{=b Kk} %n%f %t %{-}%+Lw %=%{= dd}"

So here's my zshrc settings to tell screen about what I'm doing in each tab.

# ~/.zshrc
# if using GNU screen, let the zsh tell screen what the title and hardstatus
# of the tab window should be.
if [[ $TERM == "screen" ]]; then
  _GET_PATH='echo $PWD | sed "s/^\/Users\//~/;s/^~$USER/~/"'

  # use the current user as the prefix of the current tab title (since that's
  # fairly important, and I change it fairly often)
  TAB_TITLE_PREFIX='"`'$_GET_PATH' | sed "s:..*/::"`$PROMPT_CHAR"'
  # when at the shell prompt, show a truncated version of the current path (with
  # standard ~ replacement) as the rest of the title.
  # when running a command, show the title of the command as the rest of the
  # title (truncate to drop the path to the command)

  # use the current path (with standard ~ replacement) in square brackets as the
  # prefix of the tab window hardstatus.
  # when at the shell prompt, use the shell name (truncated to remove the path to
  # the shell) as the rest of the title
  # when running a command, show the command name and arguments as the rest of
  # the title

  # tell GNU screen what the tab window title ($1) and the hardstatus($2) should be
  function screen_set()
    # set the tab window title (%t) for screen
    print -nR $'\033k'$1$'\033'\\\

    # set hardstatus of tab window (%h) for screen
    print -nR $'\033]0;'$2$'\a'
  # called by zsh before executing a command
  function preexec()
    local -a cmd; cmd=(${(z)1}) # the command string
    eval "tab_title=$TAB_TITLE_PREFIX$TAB_TITLE_EXEC"
    screen_set $tab_title $tab_hardstatus
  # called by zsh before showing the prompt
  function precmd()
    screen_set $tab_title $tab_hardstatus

The most useful screen customization, IMHO, is to change the modifier key to something other than C-a. That is just too important of a key to have eaten (go to the beginning of the line at all readline prompts, and in emacs). I use C-z, since I need to suspend applications a lot less often than I need to edit something at the beginning of the line.

The magic word is:

escape ^za
  • 1
    i set mine to ctrl-K because it's the least commonly used ctrl key in the apps that i use. ^A is too useful in bash/readline to sacrifice. – cas Jul 18 '09 at 5:09
  • 1
    To check what you clash with you could consult… (which I asked with this in mind). – Hamish Downer Jun 24 '10 at 21:22
  • 2
    FYI, If you want to leave C-a as the moderator key, C-a a will go to the beginning of the line. It took me a while to figure this out. – Coomer Nov 17 '12 at 21:29

I often have more than 10 windows running and wanted a way to select them. I found out how to configure C-a Shift+0 through 9 to select windows 10 through 19.

bind  ! select 11
bind  @ select 12
bind \# select 13
bind  $ select 14
bind  % select 15
bind \^ select 16
bind  & select 17
bind  * select 18
bind  ( select 19
bind  ) select 10

Note the escapes on # and ^.

Sick of full-screen programs like vim remaining in the scrollback buffer after you've closed them? Wouldn't it be great if they'd go away completely just like they do when you're not running screen? Try putting this in your ~/.screenrc file...

altscreen on

I'm using Ctrl+Alt+Left and Ctrl+Alt+Right to switch between screen windows. For my IRSSI channel I use Alt+Left and Alt+Right, and for GNOME workspace switching I use Ctrl+Alt+Shift+Left/Right. It seems complicated, but it actually works really well.

The character codes for the GNOME terminal are different from the character codes when connecting through PuTTy, so I had to duplicate the entries. You can use cat > /dev/null to find out the appropriate character codes for you.

# execute 'cat > /dev/null' to see the character codes

# Change Escape Combination to Ctrl+f (Ctrl+a is too useful to lose)
escape ^Ff

# Ctrl + Alt + Left from gnome-terminal
bindkey ^[[1;7C prev

# Ctrl+Alt+Left from putty
bindkey ^[^[[D prev

# Ctrl + Alt + Right from gnome-terminal
bindkey ^[[1;7D next

# Ctrl+Alt+Right from putty
bindkey ^[^[[C next

The backtick command is pretty groovy. Read about it in man screen. I use it like so:

backtick 1 15 15 $HOME/bin/cpuusage
# now add '%1`%% CPU' to your hardstatus string. Result is like 38.4% CPU.

My cpuusage script for Linux and Mac is:

if [[ $(uname) == "Darwin" ]]; then
    top -i1 -l2 -n0|awk '/CPU/{i+=1; gsub(/%/,"",$0);p=substr(sprintf("%3.2f",$8+$10),0,4);if(i==2){printf "%g", p}}'
    awk 'NR==1 {p=substr(sprintf("%3.2f", ($2+$3)/($2+$3+$4+$5)*100),0,4); printf "%g", p;}'</proc/stat

I also can't live without the menu bar. One thing I do not like putting on the menu which a lot of people have is the time; it prevents PuTTY's scroll back from staying scrolled back (since it's considered a screen update)

  • 1
    You could use screen's inbuilt scrollback? C-A [ by default will put you into copy mode, and will allow you to navigate your current tab using keyboard commands like a text editor? – Murali Suriar May 28 '09 at 11:19
  • @murail I prefer using the scrolly wheel thingy in my mouse when I'm using putty; just habit. @mikeage -- I found that if you get rid of the seconds on the clock it makes the scrollback buffer on screen work pretty well. Of course, I mostly have a clock on my screen to avoid the stupid idle timeouts we've got on our damned firewalls. grrr. – chris Apr 20 '11 at 12:20

I have F11 and F12 set to cycle through windows, makes it quicker to move between windows, especially for windows > 10

# Bind F11 and F12 (NOT F1 and F2) to previous and next screen window
bindkey -k F1 prev
bindkey -k F2 next

If you are using urxvt, the following will allow CTRL+LEFT and CTRL+RIGHT to be used to move to the previous and next tab window:

bindkey "^[Od" prev  # ctrl-left
bindkey "^[Oc" next  # ctrl-right

Reconnecting to a remote screen session that should always be running or immediately created:

bind V screen -t MYTABNAME ssh -t MYUSERNAME "screen -x main || screen -R -S main"

Turning flow control off by default allows you to use CTRL+R in rtorrent properly:

defflow off

If running rtorrent as a daemon with its own user account, this .screenrc can be useful:

vbell off
startup_message off
escape ^Rr
screen -t rtorrent rtorrent
multiuser on
defflow off

Based on answers to How to force Gnu screen to load my bash .profile, I would add:

shell -$SHELL

to your ~/.screenrc to make screen start login shells. This is very useful if you want your ~/.bash_profile executed when you use the shell through screen.

# disable C-a s, which freezes the screen; can be resolved with C-a q
bind s 

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