commit 7e17c4aeb6ad98e3daff5ea10dc5e2f7edea8325 Author: Jaidyn Levesque Date: Tue Mar 24 17:39:47 2020 -0500 Init diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..642c22d --- /dev/null +++ b/README.txt @@ -0,0 +1,56 @@ +=============================================================================== +TIINT tmux for ii +=============================================================================== + +A tmux "client" for use with suckless' IRC It. + +Simple script that'll make tmux windows for IRC channels with two panes: +- one for tail'ing the output +- one for getting user input + +It's pretty POSIX, and'll run on both GNU and BSD systems. + +It also kinda supports notifications, see CONFIG below. + + +---------------------------------------- +USAGE +---------------------------------------- +It can make a window for a single channel; windows for every channel in a +server; or windows for all channels under all servers of an irc root. + +$ tiint -i $IRC_ROOT +$ tiint -s $SERVER_ROOT +$ tiint -c $CHANNEL_PATH + +Personally I do: +$ tiint -i ~/chat/irc/ +or +$ tiint -c ~/chat/irc/irc.freenode.net/#hase + + +---------------------------------------- +INSTALL +---------------------------------------- +Just put `tiint` and `loop_input.sh` in your path. +If you want notifications, put in `diff_monitor.sh` too. + + +---------------------------------------- +CONFIG +---------------------------------------- +There's no "config", but you can edit the script if you want. It's lightweight +and you can do whatever probably. + +What you might be interested in doing is enabling notifications (uncomment +the line that calls "diff_monitor" in `tiint`), then configuring your +preferred notifcation method (zenity, beeping, whatever) by editing the +"notify" function of `diff_monitor.sh`. + + +---------------------------------------- +BORING STUFF +---------------------------------------- +License is CC-0 +Author is Jaidyn Ann +Sauce is at https://git.xwx.moe/tiint diff --git a/diff_notify.sh b/diff_notify.sh new file mode 100644 index 0000000..8a477ac --- /dev/null +++ b/diff_notify.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# name: diff_notify.sh +# desc: monitor a file for changes; then notify the user when it changes +# by default it makes your PC beep a couple times +# lisc: cc0 + +# FILEPATH -> SHA256_HASH +# get a file's hash, using the proper program +function file_hash { + local file="$1" + local hash="$(sha256sum "$file" 2>/dev/null | awk '{print $1}' 2>/dev/null)" + if test -z "$hash"; then + hash="$(sha256 -q "$file" 2>/dev/null)" + fi + echo "$hash" +} + +# NIL -> NIL +# beeps even on systems without the beep command +function true_beep { + if beep 2>/dev/null; then printf '\007\n'; fi +} + +# FILEPATH -> NIL +# monitor a file for changes 'till death, notify the user when it changes +function monitor_file { + local file="$1" + local old_hash="$(file_hash "$file")" + local new_hash="$old_hash" + echo "monitoring $file" + while test 1 -eq 1; do + old_hash="$new_hash" + new_hash="$(file_hash "$file")" + if test "$old_hash" != "$new_hash"; then + notify "$file" "$(tail -1 "$file")" + fi + sleep 5 + done +} + +# HEADER MESSAGE -> ?? +# notify the user *somehow*-- depending on what's uncommented +function notify { + local header="$1" + local message="$2" + ## As you can tell, there are a bunch of ways to be notified. =w= + # notify-send "$header" "$message" + # zenity --notification --text="$header" + # mpv ~/.notification.ogg + true_beep; true_beep +} + +# INVOCATION +# ================== +FILE="$1" +monitor_file "$FILE" diff --git a/loop_in.sh b/loop_in.sh new file mode 100755 index 0000000..0167e9f --- /dev/null +++ b/loop_in.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# name: loop_in +# desc: literally just keeps reading input to the given file, invoking itself + +# FILEPATH -> NIL +# output user input to given file +function input_to_file { + file="$1" + printf '%s > ' "$file" + read message + echo "$message" >> "$OUTFILE" +} + +# INVOCATION +# ================== + +OUTFILE="$1" +while test 1 -eq 1; do + input_to_file "$OUTFILE" +done diff --git a/tiint b/tiint new file mode 100755 index 0000000..6d108ae --- /dev/null +++ b/tiint @@ -0,0 +1,59 @@ +#!/bin/sh +# name: tiint.sh +# desc: a simple script for setting up a tmux session for your `ii` stuff +# can run on servers, channels, or irc roots +# just opens up `tail` on outfile and reads to infile +# main: jaidyn ann +# lisc: CC0 i guess + + +# CHANNEL_PATH -> NIL +# makes a new tmux window for the channel at given path; one pane for tailing +# it, one for user input with loop_in.sh +function make_channel_window { + channel="$1" + tmux neww tail -f ${channel}/out + tmux splitw -p 10 diff_notify.sh ${channel}/out + tmux splitw -p 10 loop_in.sh ${channel}/in +} + +# SERVER_PATH -> NIL +# make tmux windows for all channels at a given server path +function make_server_windows { + server="$1" + cd "$server" + for channel in ./#*; do + make_channel_window "$(basename "$channel")" + done +} + +# IRC_PATH -> NIL +# make tmux windows for all servers and channels at a given IRC root +function make_irc_windows { + ircroot="$1" + cd "$ircroot" + for server in ./*; do + if test -d "$server"; then + make_server_windows "$server" + fi + done +} + +# INVOCATION +# ================== + +function help { + echo "usage: $(basename "$0") -i IRC_PATH" + echo " $(basename "$0") -s SERVER_PATH" + echo " $(basename "$0") -c CHANNEL_PATH" +} + + +while getopts 'i:s:c:h' c; do + case "$c" in + h) help; exit 2 ;; + i) make_irc_windows "$OPTARG" ;; + s) make_server_windows "$OPTARG" ;; + c) make_channel_window "$OPTARG" ;; + esac +done