Skip to content

Commit

Permalink
Merge pull request #56 from zsprackett/source_friendly
Browse files Browse the repository at this point in the history
Fix it so that sourcing works properly
  • Loading branch information
holman committed Dec 12, 2012
2 parents 643bbdc + 1912376 commit 8faddf9
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions spark
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@
# spark -h
# # => Prints the spark help text.

# Prints the help text for spark.
help()
{
cat <<EOF
USAGE:
spark [-h] VALUE,...
EXAMPLES:
spark 1 5 22 13 53
▁▁▃▂█
spark 0,30,55,80,33,150
▁▂▃▄▂█
echo 9 13 5 17 1 | spark
▄▆▂█▁
EOF
}

# Generates sparklines.
#
# $1 - The data we'd like to graph.
Expand Down Expand Up @@ -77,13 +59,31 @@ spark()
}

# If we're being sourced, don't worry about such things
[[ ${#BASH_SOURCE[@]} -eq 1 ]] || return
if [ "$BASH_SOURCE" == "$0" ]; then
# Prints the help text for spark.
help()
{
cat <<EOF
# show help for no arguments if stdin is a terminal
if { [ -z "$1" ] && [ -t 0 ] ; } || [ "$1" == '-h' ]
then
help
exit
fi
USAGE:
spark [-h] VALUE,...
EXAMPLES:
spark 1 5 22 13 53
▁▁▃▂█
spark 0,30,55,80,33,150
▁▂▃▄▂█
echo 9 13 5 17 1 | spark
▄▆▂█▁
EOF
}

spark ${@:-`cat`}
# show help for no arguments if stdin is a terminal
if { [ -z "$1" ] && [ -t 0 ] ; } || [ "$1" == '-h' ]
then
help
exit
fi

spark ${@:-`cat`}
fi

0 comments on commit 8faddf9

Please sign in to comment.