aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-01-23 12:38:54 +0000
committerJoursoir <chat@joursoir.net>2021-01-23 12:38:54 +0000
commita6e8585253899160fdf25300c91a22a1b5edfa4a (patch)
tree08a75c60a8239d40b02acc0d89b7490155ed63ea
parent90789b56c9d7b96903b2287b960afb9755026e8f (diff)
downloadspark-a6e8585253899160fdf25300c91a22a1b5edfa4a.tar.gz
spark-a6e8585253899160fdf25300c91a22a1b5edfa4a.tar.bz2
spark-a6e8585253899160fdf25300c91a22a1b5edfa4a.zip
add: work with stdin, determinate system bits, help
-rwxr-xr-xspark.sh57
1 files changed, 41 insertions, 16 deletions
diff --git a/spark.sh b/spark.sh
index b7add42..ceac7b4 100755
--- a/spark.sh
+++ b/spark.sh
@@ -1,5 +1,33 @@
#!/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 [number] [number] [number] ...
+ EOF
+ exit 0
+fi
+
case `uname -m` in
x86_64|amd64) # 64 bit
MAX=$(( -2**63 ));
@@ -12,29 +40,26 @@ case `uname -m` in
MIN=$(( 2*15-1 )) ;;
esac
-for i in "$@"
-do
- case $i in
- ''|*[!0-9]*) exit 1 ;;
- *) ;;
- esac
-
- if [ $i -gt $MAX ]; then
- MAX=$i
- fi
- if [ $i -lt $MIN ]; then
- MIN=$i
- fi
-done
+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 "$@"
+for i in "${array[@]}"
do
H=$(( 1 + ($i - $MIN + 1) * ($LEVELS-1) / $DIFF ))
printf "\u258$H"
done
-echo \ No newline at end of file
+echo
+exit 0 \ No newline at end of file