Source

pcw / extras / cw_color.sh

Evan Gates 828493a 
Evan Gates 79c4845 
Evan Gates 828493a 
Evan Gates 4462202 
Evan Gates e31d01d 
Evan Gates 9c1102c 
Evan Gates aa82d9b 

Evan Gates a7e8606 
Evan Gates aa82d9b 
Evan Gates 828493a 
Evan Gates e31d01d 
Evan Gates aa82d9b 
Evan Gates eeb198e 



Evan Gates e31d01d 
Evan Gates 9c1102c 



Evan Gates e31d01d 
Evan Gates 828493a 
Evan Gates aa82d9b 
Evan Gates 828493a 
Evan Gates a1be3b4 
Evan Gates aa9ae1b 

Evan Gates 79c4845 
Evan Gates aa9ae1b 

Evan Gates 181cfa8 
Evan Gates aa9ae1b 


Evan Gates 79c4845 
Evan Gates aa9ae1b 



Evan Gates 828493a 
Evan Gates eeb198e 


Evan Gates aa82d9b 








Evan Gates f09b27b 
Evan Gates aa9ae1b 
Evan Gates 79c4845 
Evan Gates 4462202 
Evan Gates 79c4845 

Evan Gates f09b27b 
Evan Gates a7e8606 




Evan Gates 828493a 





Evan Gates 9c1102c 
Evan Gates 99b91d9 
Evan Gates eeb198e 

Evan Gates 79c4845 
Evan Gates 828493a 
Evan Gates aa82d9b 
Evan Gates 4462202 
Evan Gates aa82d9b 

Evan Gates 828493a 





Evan Gates aa82d9b 
Evan Gates 828493a 
#!/bin/bash

PAD=12
NICK="$USER"

# NOTE: make sure you have a 256 color terminal, or change these options
# to find out which colors are readable...
# for i in {0..255}; do echo $(tput setaf $i) $i foobar baz qux; done
colors=({9..11} {13..14} {26..51} {62..87} 99 {105..123} {130..159} {165..231})
declare -A color_cache

reset="$(tput sgr0)"
red="$(tput setaf 9)"
cyan="$(tput setaf 14)"
magenta="$(tput setaf 13)"
green="$(tput setaf 10)"
yellow="$(tput setaf 11)"

action="$magenta*$cyan*$yellow*"  # used to prefix CTCP actions
notice_fmt="$(tput setaf 239)"    # used for time, and join/part/quit/etc. messages
my_nick_fmt="$red$(echo -e "\a")" # how to highlight your nick when someone mentions it
my_line_fmt="$cyan"               # how you want your own lines to appear

format=""
cols="132"

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

set_format() {
	if [ "$*" = "-!-" ]; then
		format="$notice_fmt"
	elif [ "$*" = "$NICK" ]; then
		format="$my_line_fmt"
	elif [ -n "${color_cache["$*"]}" ]; then
		format=${color_cache["$*"]}
	else
		chksm="$(echo "$*" | cksum | sed "s/^0\+//; s/ .*$//")"
		chksm=$((chksm % ${#colors[@]}))
		format="$(tput setaf ${colors[$chksm]})"
		color_cache["$*"]=$format
	fi
}

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

	if [ "$date" = "SIZE" ]; then
		cols=$nick
		continue
	fi

	if [ ${#nick} -lt $PAD ]; then
		head_len=$(($PAD + ${#time} + 2))
	else
		head_len=$((${#nick} + ${#time} + 2))
	fi

	time="${notice_fmt}${time}${reset}"

	set_format "$nick"
	nick=$(printf "%s%${PAD}s%s |%s" "$format" "$nick" "$reset" "$format")

	first=1
	echo "$msg" | fmt -w $((cols - head_len - 1)) -s |
	while read -r line; do
		line=${line//$NICK/$reset$my_nick_fmt$NICK$reset$format}
		line=${line/#ACTION/"$action$reset$format"}
		if [ -n "$first" ]; then
			printf "%s %s %s\n" "$time" "$nick" "$line$reset"
			first=""
		else
			printf "%${head_len}s| %s\n" "" "$format$line$reset"
		fi
	done
done
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.