screen setup with custom hard status and dialog menu

The following set of scripts produce a nice screen setup along with a dialog menu for the most common tasks.

This is how it looks like

And this is how it’s done. Please see inline comments for details.

## use shift-left/right to switch between windows
## use ctrl-n to add new shellwindow
## use shift-PgUp/PgDown for scrolling history hit esc to stop
## use ctrl-a-k for killing a window
## mark area with space, end marking with space, paste with ctrl-a-]
setenv TERM xterm

#kill startup messes
startup_message off

# detach on hangup
autodetach on

# define a bigger scrollback, default is 100 lines
defscrollback 4096

# shell
shell -bash

#make scrollbar work
termcapinfo xterm ti@:te@

defmonitor on                   # turn monitoring on
activity "%"                    # tell me when stuff happens!

# Make shift-PgUp and shift-PgDn work like they do in xterm.  (Note that this
# requires xterm to be configured to pass those keys through, and not try to
# act on them itself.)
bindkey "^[O2A" eval "copy" "stuff ^b"
bindkey -m "^[O2A" stuff ^u
bindkey -m "^[O2B" stuff ^d

bindkey "^[O2D" prev
bindkey "^[O2C" next

# ctrl-N for new window
bindkey "^N" screen

# ctrl-a-b to copy selection to osx-clipboard
#bind b eval "writebuf" "exec sh -c 'pbcopy < /tmp/screen-exchange'"

# Window numbering starts at 1, not 0.
bind c screen 1
bind 0 select 10

# Run everything in UTF-8.
defutf8 on
# If a window goes unresponsive, don't block the whole session waiting for it.
nonblock on

# An alternative hardstatus to display a bar at the bottom listing the
# windownames and highlighting the current windowname in blue. (This is only
# enabled if there is no hardstatus setting for your terminal)
# see
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "

screen -t selector sh

I use this via screen -c selector-screenrc. The helper script for initializing a screen session looks like this and would either connect to an existing one or create a new one.


screenpid=`ps x|grep -E '(.*)SCREEN(.*)selector-screenrc\$'|awk '{print \$1}'|head -1`
if [ $screenpid -gt 0 ]; then
        screen -x $screenpid -c selector-screenrc
        screen -c selector-screenrc

The file is a bonus and provides a dialog menu for frequently used commands. It looks like this


while [ 1 ]; do

select=`/opt/local/bin/dialog --stdout --menu "select task" 20 60 13 \`cat tasks | tr '\040' '_' | tr '\012' '\040'\``

echo "selected $select"

if [ ! -z $select ]; then 

	echo $select

	command=`grep $select tasks|awk 'BEGIN{FS=OFS="\t"}{print \$2}'|tr -d "\""`

	echo "executing command \"$command\""

#	sleep 2
	exit 0


The “tasks” file holds a simple list of tasks/commands. See the example below.

su		"screen -t rootshell sudo su -"
newshell	"screen -t shell"