insomnia

A frontend for the hii IRC client

git clone https://git.8pit.net/insomnia.git

 1#!/bin/sh
 2set -e
 3
 4if [ $# -lt 1 ]; then
 5	echo "USAGE: ${0##*/} SERVER [CHANNEL]" 1>&2
 6	exit 1
 7fi
 8
 9export PATH="${PATH}:@LIBDIR@"
10export INPUTRC="@DATADIR@/inputrc"
11export INSOMNIA_BASE="${INSOMNIA_BASE:-$HOME/irc}"
12export INSOMNIA_DIR="${INSOMNIA_BASE}/${1}/${2}"
13
14# tmux doesn't copy environment variables, pass them explicitly.
15vars="PATH='${PATH}' INPUTRC='${INPUTRC}' INSOMNIA_BASE='${INSOMNIA_BASE}' INSOMNIA_DIR='${INSOMNIA_DIR}'"
16
17if [ ! -d "${INSOMNIA_DIR}" ]; then
18	echo "'${INSOMNIA_DIR}' isn't a directory or doesn't exist" 1>&2
19	exit 1
20fi
21
22while [ ! -p "${INSOMNIA_DIR}/in" ]; do
23	echo "Input FIFO doesn't exist yet, sleeping..." 1>&2
24	sleep 3
25done
26
27# insomnia tries to mimic a TUI IRC client. As such, there should only
28# be a single insomnia session at a time. For this reason, the session
29# name is not unique and the session is killed automatically on detach.
30session="insomnia"
31
32if tmux has-session -t "=${session}" >/dev/null 2>&1; then
33	echo "An insomnia tmux session does already exits" 1>&2
34	exit 1
35fi
36
37exec 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