Source

pcw / extras / cw_color.sh

Full commit
#!/bin/sh

PAD=10
NICK=emg

reset="$(tput sgr0)"
bold="$(tput bold)"
black="$(tput setaf 0)"
red="$(tput setaf 1)"
magenta="$(tput setaf 5)"

me_fmt="${red}\a"

while [ $# -gt 0 ]; do
	case $1 in
		-i) IN="$2"
		   	;;
		-o) OUT="$2"
			;;
		-n) NICK="${2:-$NICK}"
			;;
		*)  echo "bad argument $1"
			exit 2
			;;
	esac
	shift 2
done

print_nick () {
	chksm="$(echo "$*" | cksum | sed "s/^0\+//; s/ .*$//")"
	chksm=$((chksm % 173 + 58))
	printf "%s%${PAD}s%s |" "$(tput setaf $chksm)" "$*" "$reset"
}

print_info() {
	echo -n "${bold}${black}$*${reset}"
}

cw "${IN:?no -i infile specified}" "${OUT:?no -o outfile specified}" |
while read date time nick msg; do
	nick=${nick#<}
	nick=${nick%>}

	time=$(print_info "$time")

	if [ "$nick" = "-!-" ]; then
		nick=$(printf "%s%$((PAD + 3))s" "${bold}${black}" "$nick")
	else
		nick=$(print_nick "$nick")
	fi

	echo "$time" "$nick" "${msg}${reset}"
done | sed "/|/s/$NICK/$me_fmt&$reset/g; /ACTION/s/| ACTION \(.*\)/${magenta}***${reset} \1/"