Commits

Evan Gates  committed cc278c3

update cw_color.sh

  • Participants
  • Parent commits 025292f

Comments (0)

Files changed (1)

 	shift 2
 done
 
+color_cache["-!-"]="$notice_fmt"
+color_cache["${NICK%_}"]="$my_line_fmt"
+
 set_format() {
-	if [ "$*" = "-!-" ]; then
-		format="$notice_fmt"
-	elif [ "${*%_}" = "$NICK" ]; then
-		format="$my_line_fmt"
-	elif [ -n "${color_cache["$*"]}" ]; then
-		format=${color_cache["$*"]}
+	if [ -n "${color_cache["${*%_}"]}" ]; then
+		format=${color_cache["${*%_}"]}
 	else
 		chksm="$(echo "$*" | cksum | sed "s/^0\+//; s/ .*$//")"
 		chksm=$((chksm % ${#colors[@]}))
 }
 
 cw "${IN:?no -i infile specified}" "${OUT:?no -o outfile specified}" |
-while read -r date time nick msg; do
+while read -r date time nick_msg; do
+	nick=${nick_msg%% *}
+	nick=${nick%>}
 	nick=${nick#<}
-	nick=${nick%>}
+	msg=${nick_msg#* }
 
 	if [ "$date" = "SIZE" ]; then
 		cols=$nick
 	nick=$(printf "%s%${PAD}s%s |%s" "$format" "$nick" "$reset" "$format")
 
 	first=1
+	oIFS="$IFS"
+	IFS="\n"
 	echo "$msg" | fmt -w $((cols - head_len - 1)) -s |
 	while read -r line; do
 		line=${line//$NICK/$reset$my_nick_fmt$NICK$reset$format}
 			printf "%${head_len}s| %s\n" "" "$format$line$reset"
 		fi
 	done
+	IFS="$oIFS"
 done