Skip to content

Commit

Permalink
retab
Browse files Browse the repository at this point in the history
  • Loading branch information
holman committed Nov 17, 2011
1 parent e22bb47 commit 388429c
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions spark
Expand Up @@ -27,7 +27,7 @@
# Prints the help text for spark.
help()
{
cat <<EOF
cat <<EOF
USAGE:
spark VALUE,...
Expand All @@ -45,37 +45,37 @@ EOF
# $1 - The data we'd like to graph.
spark()
{
local n numbers=
local n numbers=

# find min/max values
local min=0xffffffff max=0
# find min/max values
local min=0xffffffff max=0

for n in ${@//,/ }
do
# on Linux (or with bash4) we could use `printf %.0f $n` here to
# round the number but that doesn't work on OS X (bash3) nor does
# `awk '{printf "%.0f",$1}' <<< $n` work, so just cut it off
n=${n%.*}
(( n < min )) && min=$n
(( n > max )) && max=$n
numbers=$numbers${numbers:+ }$n
done
for n in ${@//,/ }
do
# on Linux (or with bash4) we could use `printf %.0f $n` here to
# round the number but that doesn't work on OS X (bash3) nor does
# `awk '{printf "%.0f",$1}' <<< $n` work, so just cut it off
n=${n%.*}
(( n < min )) && min=$n
(( n > max )) && max=$n
numbers=$numbers${numbers:+ }$n
done

# print ticks
local ticks=(▁ ▂ ▃ ▄ ▅ ▆ ▇ █)
local f=$(( (($max-$min)<<8)/(${#ticks[@]}-1) ))
(( f < 1 )) && f=1
# print ticks
local ticks=(▁ ▂ ▃ ▄ ▅ ▆ ▇ █)
local f=$(( (($max-$min)<<8)/(${#ticks[@]}-1) ))
(( f < 1 )) && f=1

for n in $numbers
do
echo -n ${ticks[$(( ((($n-$min)<<8)/$f) ))]}
done
echo
for n in $numbers
do
echo -n ${ticks[$(( ((($n-$min)<<8)/$f) ))]}
done
echo
}

[ "$1" == '-h' ] && {
help
exit
help
exit
}

spark ${@:-`cat`}

0 comments on commit 388429c

Please sign in to comment.