iid

#!/usr/bin/env rc
# (re-)starts ii irc client
if (test -z $1 || test -z $2) {
  echo 'Usage: '^$0^' [USERNAME] [SERVER]' >[1=2]
  exit 1
}
USERNAME=$1
SERVER=$2
fn sigexit sigint sigquit sigtrap sighup {
  test $apids && kill -$apids
}
fn _ts {
  date '+%Y-%m-%d %H:%M' | head -c 16
}
tail -n0 -f $HOME/irc/^$SERVER^/*/out $HOME/irc/^$SERVER^/out &
while () {
  if (lsof -Fc $HOME/irc/^$SERVER^/in | grep -q cii) {
    echo ``(){_ts}^' ii(1) already connected to '^$SERVER^'.' >[1=2]
    exit 1
  }
  if (! ping -c1 -w1 $SERVER >/dev/null >[2=1]) {
    echo ``(){_ts}^' Can not connect to '^$SERVER^'.' >[1=2]
    exit 1
  }
  echo ``(){_ts}^' Connecting to '^$SERVER^' as '^$USERNAME^'.' >[1=2]
  ii -s $SERVER -n $USERNAME
}