commit e85fc97c222c229b499bd77e5abae49e508d8db6
parent df1660e71f6f8937498e7fe2691778c631209340
Author: sin <sin@2f30.org>
Date: Mon, 14 Apr 2014 23:52:28 +0100
Break hysteria into multiple shell scripts
Diffstat:
5 files changed, 68 insertions(+), 40 deletions(-)
diff --git a/config b/config
@@ -0,0 +1,2 @@
+nick="your_nickname"
+fullname="your_fullname"
diff --git a/connectserver b/connectserver
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+if test -z $1; then
+ echo "usage: $(basename $0) host" 1>&2
+ exit 1
+fi
+
+tmux list-sessions -F '#S' 2>/dev/null | \
+ grep '^hysteria' >/dev/null 2>/dev/null
+if [ $? -eq 1 ]; then
+ echo no hysteria session running 1>&2
+ exit 1
+fi
+
+. ./config
+
+host="$1"
+tmux new-window "ii -i irc -s $host -n $nick -f $fullname"
+./waitfile "irc/$host/out"
+tmux new-window "tail -f irc/$host/out | ./hiii"
+tmux split-window -p 1 "cat > irc/$host/in"
+tmux rename-window "$host"
diff --git a/hysteria b/hysteria
@@ -1,44 +1,10 @@
#!/bin/sh -x
-nick="your_nickname"
-fullname="your_fullname"
+. ./config
-waitfile() {
- while :; do
- if test -e "$1"; then
- break
- fi
- sleep 1
- done
-}
+rm -rf irc
+tmux new-session -s hysteria -d ./monitor
+tmux rename-window "event-monitor"
-init() {
- rm -rf irc
- tmux new-session -s hysteria -d ./monitor
- tmux rename-window "event-monitor"
-}
-
-connectserver() {
- host="$1"
- tmux new-window "ii -i irc -s $host -n $nick -f $fullname"
- waitfile "irc/$host/out"
- tmux new-window "tail -f irc/$host/out | ./hiii"
- tmux split-window -p 1 "cat > irc/$host/in"
- tmux rename-window "$host"
-}
-
-join() {
- host="$1"
- shift
- for c in $*; do
- echo "/join $c" > "irc/$host/in"
- waitfile "irc/$host/$c/out"
- tmux new-window "tail -f irc/$host/$c/out | ./hiii"
- tmux split-window -p 1 "cat > irc/$host/$c/in"
- tmux rename-window "$c"
- done
-}
-
-init
-connectserver "irc.freenode.net"
-join "irc.freenode.net" "#2f30" "#ninja-turtles"
+./connectserver "irc.freenode.net"
+./join "irc.freenode.net" "#2f30" "#ninja-turtles"
diff --git a/join b/join
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+if test $# -lt 2; then
+ echo "usage: $(basename $0) host channel..." 1>&2
+ exit 1
+fi
+
+tmux list-sessions -F '#S' 2>/dev/null | \
+ grep '^hysteria' >/dev/null 2>/dev/null
+if [ $? -eq 1 ]; then
+ echo no hysteria session running 1>&2
+ exit 1
+fi
+
+. ./config
+
+host="$1"
+shift
+for c in $*; do
+ echo "/join $c" > "irc/$host/in"
+ ./waitfile "irc/$host/$c/out"
+ tmux new-window "tail -f irc/$host/$c/out | ./hiii"
+ tmux split-window -p 1 "cat > irc/$host/$c/in"
+ tmux rename-window "$c"
+done
diff --git a/waitfile b/waitfile
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+if test -z $1; then
+ echo "usage: $(basename $0) file" 1>&2
+ exit 1
+fi
+
+while :; do
+ if test -e "$1"; then
+ break
+ fi
+ sleep 1
+done