Created
March 31, 2011 19:19
-
-
Save akrito/897027 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansi_hash () { | |
# Colors a string based on a hash of its contents | |
# Usage: ansi_hash [-s style] [-o offset] text .. | |
style=0 # default is normal, 1 is bold, 4 is underline | |
offset=30 # default is normal, 90 is high intensity | |
OPTIND=0 | |
while getopts s:o: a | |
do case "$a" in | |
s) style="$OPTARG";; | |
o) offset="$OPTARG";; | |
[?]) print >&2 "Usage: $0 [-s style] [-o offset] text ...";; | |
esac | |
done | |
shift `expr $OPTIND - 1` | |
hashme="$@" | |
hex=`echo "$hashme" | md5sum | cut -b 1-6` | |
decimal=$((0x$hex)) | |
part=`expr $decimal % 8 + $offset` | |
printf '\e[%s;%sm%s\e[0m' $style $part $hashme | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment