-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshacolor
executable file
·69 lines (59 loc) · 1.1 KB
/
shacolor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -eu
NUM=1
if [ $# -ge 1 ]; then
case "$1" in
-1) NUM=1 ; shift ;;
-2) NUM=256 ; shift ;;
-224) NUM=224 ; shift ;;
-256) NUM=256 ; shift ;;
-384) NUM=384 ; shift ;;
-512) NUM=512 ; shift ;;
esac
fi
case "$NUM" in
224) rows=2; cols=14 ;;
256) rows=2; cols=16 ;;
384) rows=3; cols=16 ;;
512) rows=4; cols=16 ;;
1) rows=1; cols=20 ;;
*)
echo >&2 "error: unexpected sha: sha$NUM"
exit 1
;;
esac
color_for_nibble() {
if [ $# -lt 1 ]; then
echo >&2 "must pass nibble"
return 1
fi
num=$((0x$1))
echo -en "\033[48;5;${num}m"
echo -n " $1 "
echo -en "\033[0m"
}
sha_prog() {
local num
num="$1"
shift
case "$OSTYPE" in
darwin*)
shasum -a "$num" "$@"
;;
*)
"sha${num}sum" "$@"
;;
esac
}
sha_prog "$NUM" "$@" | while read hash filename; do
echo "$hash $filename"
i=0
for (( row=0; row < rows; row++ )); do
for (( col=0; col < cols; col++ )); do
color_for_nibble "${hash:$i:2}"
i=$((i + 2))
done
echo ''
done
done
# vim: set sw=2 ts=2 :