Permalink
Browse files

Merge pull request #56 from zsprackett/source_friendly

Fix it so that sourcing works properly
  • Loading branch information...
2 parents 643bbdc + 1912376 commit 8faddf9faf78fe74ac4f48f550e57641381e45a2 @holman committed Dec 12, 2012
Showing with 26 additions and 26 deletions.
  1. +26 −26 spark
View
@@ -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.
@@ -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.