Skip to content

Instantly share code, notes, and snippets.

@c00kiemon5ter
Created January 10, 2013 16:59
Show Gist options
  • Save c00kiemon5ter/4503769 to your computer and use it in GitHub Desktop.
Save c00kiemon5ter/4503769 to your computer and use it in GitHub Desktop.
iii alike frontend for sic
#!/usr/bin/env sh
: "${c:=12}" # max channel width
: "${n:=12}" # max user name width
: "${p:=1}" # prettify - colors and stuff
: "${w:=110}" # max mesg width
: "${s:="|"}" # the separator
trap "stty '$(stty -g)'; kill -TERM 0" EXIT
stty -echonl -echo
usage() {
printf '%s\n' "sic.sh [-h host] [-p port] [-n nick] [-k pass]" >&2
exit 1
}
while [ -n "$1" ]; do
if [ -z "$2" ]; then
printf 'sic.sh: no argument for option: %s\n' "$1" >&2
usage
fi
case "$1" in
-h)
host="$2"
;;
-p)
port="$2"
;;
-n)
nick="$2"
;;
-k)
pass="$2"
;;
*)
printf 'sic.sh: unknown option: %s\n' "$1" >&2
usage
;;
esac
shift 2
done
[ -z "$host" ] && host='chat.freenode.net'
[ -z "$port" ] && port='6667'
[ -z "$nick" ] && nick="$USER"
rlwrap -a -s 100 sic -h "$host" -p "$port" -n "$nick" -k "$pass" | while IFS= read -r line
do
unset chan date time user comm prms mesg
unset chanclr dateclr userclr mesgclr
chan="${line%%:*}" line="${line#*: }" chan="${chan%% *}"
date="${line%% *}" line="${line#* }"
time="${line%% *}" line="${line#* }"
user="${line%% *}" line="${line#* }"
if [ "$user" != '><' ]
then user="${user#<}" user="${user%>}"
else
comm="${line%% *}" line="${line#* (}"
prms="${line%%)*}" line="${line#*): }"
if [ -n "${chan%%#*}" -a "${chan}" != "${nick}" ]
then
user="${chan}"
chan="${prms%% *}"
line="${comm} ${line:-"${prms#* }"}"
fi
fi
echo "$line" | fold -s -w "$w" | while IFS= read -r mesg; \
do
# handle ACTION messages
case "$mesg" in
ACTION*)
mesg="${user} ${mesg#ACTION}"
user='*'
;;
esac
# prettify - colors and stuff
if [ "$p" -ne 0 ]
then
dateclr="$(tput setaf 6)"
chanclr="$(tput setaf $(( $(printf '(%d + %d)' "${#chan}" "'${chan}") % 14 + 1)))"
seprclr="$(tput setaf 6)"
if [ "$user" != '><' ]
then
userclr="$(tput setaf 2)"
case "$mesg" in *${nick}*) dateclr="$(tput setaf 3)" ;; esac
else userclr="$(tput setaf 14)"
fi
if [ -n "$comm" ]
then mesgclr="$(tput setaf 8)"
else mesgclr="$(tput setaf 7)"
fi
fi
printf '\r%s%s %s %s%*.*s %s%*.*s %s%s %s%s%s\n' \
"$dateclr" "$date" "$time" \
"$chanclr" "$c" "$c" "$chan" \
"$userclr" "$n" "$n" "$user" \
"$seprclr" "$s" \
"$mesgclr" "$mesg" "$(tput sgr0)"
done
[ "${line%%:*}" = 'ERROR Closing Link' ] && exit
done
@c00kiemon5ter
Copy link
Author

screenshot here

using #ubuntu as a high-traffic channel -- you won't find me there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment