aboutsummaryrefslogtreecommitdiffstats
path: root/spark.sh
blob: 6e192276a2e0087e83421826a6c49e4c2c48c3f6 (plain)
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
#!/usr/bin/env bash

function add_to_array() {
	case $1 in
		*[!0-9]*) exit 1 ;;
		*) ;;
	esac
	array+=( $1 )

	if [ $1 -gt $MAX ]; then
		MAX=$1
	fi
	if [ $1 -lt $MIN ]; then
		MIN=$1
	fi
}

if [ -t 0 ] && [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]
then
	cat <<-EOF
		Spark

		Code was written by Joursoir <chat@joursoir.net>
		This is free and unencumbered software released into the public domain.

		Synopsis: spark [-h|--help] [number] ...
		EOF
	exit 0
fi

case `uname -m` in
	x86_64|amd64) # 64 bit
		MAX=$(( -2**63 ));
		MIN=$(( 2**63-1 )) ;; 
	i686|i386|x86) # 32 bit
		MAX=$(( -2**31 ));
		MIN=$(( 2**31-1 )) ;;
	*) # 16 bit
		MAX=$(( -2*15 ));
		MIN=$(( 2*15-1 )) ;;
esac

if [ $# -gt 1 ]
then
	for i in "$@"; do
		add_to_array $i
	done
else
	while read -r i; do
		add_to_array $i
	done
fi

LEVELS=8
DIFF=$(( $MAX - $MIN + 1 ))

for i in "${array[@]}"
do
	H=$(( 1 + ($i - $MIN + 1) * ($LEVELS-1) / $DIFF ))

	printf "\u258$H"
done

echo
exit 0