Monday, August 6, 2007

My GNU Screen Config

GNU ScreenGNU Screen is one of the most useful utilities on a *nix system. On OpenBSD, it's an installable package ("sudo pkg_add -i screen") and it's almost always the first package I install.

Scott (whose blog is not as fast as mine) and I played around with our ${HOME}/.screenrc and Scott helped me come up with this:
shell -$SHELL
startup_message off
defscrollback 1000
hardstatus alwayslastline '%{= wk}%?%-Lw%?%{r}(%{k}%n*%f%t%?(%u)%?%{r})%{k}%?%+Lw%?%?%= %m/%d %C%A'
activity ''
termcapinfo xterm* 'hs:ts=\\E]2;:fs=\07:ds=\\E]2;screen\07'

File explanation:

  1. "shell -${SHELL}" tells screen not only to use my default shell, but the "-" tells it to use it as a login shell (parsing my start-up scripts).

  2. "startup_message off" tells screen that I don't want to read the license each time I run screen. I agree. I agree.

  3. "defscrollback 1000" tells screen to increase the scrollback buffer from the default (100).

  4. The "hardstatus alwayslastline" tells screen that I want a status line at the bottom of the screen and the other text specifies that I want screen to display the screen window names/numbers and the date/time.

  5. "activity ''" tells screen not to display text when a monitored window has activity (only change its indicator on the status line)

  6. "termcapinfo xterm*" tells screen to update the titlebar for OS X's Terminal.

Here are some of my screen "tips and tricks", including some basics:

  • To create a new screen window, press ^a^c (that's Control+a, Control+c)

  • To swap between the current window and the previous one: ^a^a

  • To switch to window 1: ^a1

  • To detach: ^a^d

  • To reattach to the only screen session running: screen -R

  • To list screen sessions: screen -ls

  • To attach to a specific session: screen -r n (where n is the PID of a screen session)

  • To detach a session attached at another login session and attach to it locally: screen -dr n

  • Split the screen into two regions: ^aS (note the capital S)

  • Swap between regions on the screen: ^a[tab] (that's Control+a, TAB)

  • Kill the current region: ^aX (capital X, note that while the region is removed from the screen, the "window" is still running)

  • Rename a window: ^aA (capital A)

  • List windows: ^a"

  • Literal Control+A: ^aa

  • To start a new screen window with a title from within screen: screen -t title command_line

  • Monitor a window for changes and note its changes with a @ in the status bar (or "sound" the bell): ^aM

There's MUCH, MUCH more to screen, but this is how I use it.