hysteria

ii wrapper script
git clone git@git.2f30.org/hysteria.git
Log | Files | Refs | README | LICENSE

hysteria-monitor (1493B)


      1 #!/bin/sh
      2 #
      3 # Monitor for private messages and/or new channels and
      4 # create a new split tmux window
      5 
      6 if [ "$1" = "" ]; then
      7 	. "$HOME/.hysteria/config"
      8 else
      9 	. "$1"
     10 fi
     11 
     12 while :; do
     13 	cd "$ircdir" 2> /dev/null && break
     14 	sleep 1
     15 done
     16 while :; do
     17 	for chan in $(find . -type d | sort 2>/dev/null); do
     18 		h=$(basename $(dirname "$chan"))
     19 		c=$(basename "$chan")
     20 		NDIR="$(readlink -f $chan)"
     21 		INFILE="${NDIR}/in"
     22 		OUTFILE="${NDIR}/out"
     23 		title="$h:$c"
     24 		if test x"$h" = x"."; then
     25 			title="$c"
     26 		fi
     27 		# find window.
     28 		foundwin=0
     29 		for t in $(tmux list-windows -F '#W'); do
     30 			if test "$t" = "$title"; then
     31 				foundwin=1
     32 				break
     33 			fi
     34 		done
     35 		# kill window.
     36 		if test $foundwin -eq 1 && test -e "${OUTFILE}" && ! test -e "${INFILE}"; then
     37 			tmux kill-window -t ":${title}"
     38 		elif test $foundwin -eq 0 && test -e "${INFILE}"; then
     39 			# window not found, create it.
     40 			CHAN="$(basename ${NDIR})"
     41 			# default inputcmd if not set in config.
     42 			if test x"${inputcmd}" = x""; then
     43 				inputcmd='cat >> "$INFILE"'
     44 			fi
     45 			# arguments are passed as environment variables to mitigate possible shell injections
     46 			tmux new-window -e "OUTFILE=$OUTFILE" -e "nick=$nick" 'tail -f "$OUTFILE" | hysteria-highlight -n "($nick)" -w "($nick)"'
     47 			tmux split-window -v -p 1 -e "CHAN=$CHAN" -e "INFILE=$INFILE" -e "OUTFILE=$OUTFILE" -e "inputcmd=$inputcmd" \
     48 				'tmux resize-pane -y 2; CHAN="$CHAN" INFILE="$INFILE" OUTFILE="$OUTFILE" eval "$inputcmd"'
     49 			tmux rename-window "$title"
     50 		fi
     51 	done
     52 	sleep 1
     53 done