1#!/bin/sh
2set -e
3
4infp="${INSOMNIA_DIR}/in"
5if [ ! -p "${infp}" ]; then
6 echo "'${infp}' isn't a FIFO or does not exist" 1>&2
7 exit 1
8fi
9
10nickfp="${INSOMNIA_DIR}/usr"
11[ -S "${nickfp}" ] || unset -v nickfp
12
13histdir="${XDG_DATA_HOME:-$HOME/.local/share}/insomnia"
14mkdir -p "${histdir}"
15
16name="$(cat "${INSOMNIA_DIR}/id" 2>/dev/null || true)"
17input -w ${nickfp:+-c "insomnia-unix '${nickfp}'"} \
18 -h "${histdir}/input-history" \
19 -p "[${name:-(status)}] " \
20 | while read -r line; do
21 # TODO: Implement shortcut commmands, e.g. `/j <CHAN>`.
22 [ -p "${infp}" ] && printf "%s\n" "${line}" > "${infp}"
23done