1#!/bin/sh2set -e34if [ $# -lt 1 ]; then5 echo "USAGE: ${0##*/} SERVER [CHANNEL]" 1>&26 exit 17fi89export PATH="${PATH}:@LIBDIR@"10export INPUTRC="@DATADIR@/inputrc"11export INSOMNIA_BASE="${INSOMNIA_BASE:-$HOME/irc}"12export INSOMNIA_DIR="${INSOMNIA_BASE}/${1}/${2}"1314# tmux doesn't copy environment variables, pass them explicitly.15vars="PATH='${PATH}' INPUTRC='${INPUTRC}' INSOMNIA_BASE='${INSOMNIA_BASE}' INSOMNIA_DIR='${INSOMNIA_DIR}'"1617if [ ! -d "${INSOMNIA_DIR}" ]; then18 echo "'${INSOMNIA_DIR}' isn't a directory or doesn't exist" 1>&219 exit 120fi2122while [ ! -p "${INSOMNIA_DIR}/in" ]; do23 echo "Input FIFO doesn't exist yet, sleeping..." 1>&224 sleep 325done2627# insomnia tries to mimic a TUI IRC client. As such, there should only28# be a single insomnia session at a time. For this reason, the session29# name is not unique and the session is killed automatically on detach.30session="insomnia"3132if tmux has-session -t "=${session}" >/dev/null 2>&1; then33 echo "An insomnia tmux session does already exits" 1>&234 exit 135fi3637exec tmux new-session -d -s "${session}" -n "monitor" \38 "exec env ${vars} insomnia-monitor" \; \39 set-hook client-detached \40 "kill-session -t '=${session}'" \; \41 set-hook -g window-resized \42 "resize-pane -t '=${session}.bottom' -y 1" \; \43 \44 new-window -a -n "chat" \45 "exec env ${vars} insomnia-output" \; \46 split-window -l 1 \47 "exec env ${vars} insomnia-input" \; \48 \49 set-option -w \50 pane-border-status top \; \51 set-option -w \52 pane-border-format "#T" \; \53 select-pane -T "" \; \54 \55 attach