#!/bin/sh
# Filename:      attach-screen
# Purpose:       multi-attach to GNU screen session, creating a new one if necessary
# Authors:       (c) Phil Gregory <phil_g@pobox.com>, (c) Michael Prokop <mika@grml.org>
# Bug-Reports:   see http://grml.org/bugs/
# License:       Taken from http://aperiodic.net/phil/configs/bin/attach-screen
################################################################################

# -U option basically means "terminal does not have UTF-8 support"
if [ x$1 = "x-U" ]; then
    unset LC_CTYPE
fi

# Bring in my ssh-agent, so screen will have it available in all windows.
if [ -x /usr/bin/keychain ] ; then
  keychain --nocolor --quiet ~/.ssh/id_rsa
  . ~/.keychain/`hostname`-sh
fi

# Not a standard environment variable, but I need it for host-dependent
# decisions in .screenrc.
export HOST=`hostname`

# multi-attach to main session, creating it if necessary.  exec to save a
# process.
[ -r /etc/grml/screenrc ] && SCREENRC='-c /etc/grml/screenrc'
exec screen -S main -xRR $SCREENRC

## END OF FILE #################################################################
