1#!/bin/sh
2set -e
3
4# Host on which insomnia / hii are runnig.
5HOST="someuser@example.org"
6
7# Relative path to hii IRC directory on the host.
8IDIR="irc"
9
10target=$(ssh "${HOST}" find "${IDIR}" -maxdepth 3 -name in -a -type p | \
11 awk -F / '{ printf("%s/%s\n", $2, $3) }' | fzf)
12
13if [ -z "${target}" ]; then
14 exit 0
15elif [ "${target}" = "${target%%/*}" ]; then
16 server="${target}"
17 target=""
18else
19 server="${target%%/*}"
20 target="${target##*/}"
21fi
22
23exec mosh "${HOST}" -- insomnia "${server}" "${target}"