Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix it so that sourcing works properly #56

Merged
merged 1 commit into from

2 participants

S. Zachariah Sprackett Zach Holman
S. Zachariah Sprackett

This commit makes sourcing spark in bash work properly and also removes the
help function when sourced so as not to pollute the namespace.

S. Zachariah Sprackett zsprackett Fix it so that sourcing works properly
This commit makes sourcing spark in bash work properly and also removes the
help function when sourced so as not to pollute the namespace.
1912376
Zach Holman holman merged commit 8faddf9 into from
Zach Holman
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 12, 2012
  1. S. Zachariah Sprackett

    Fix it so that sourcing works properly

    zsprackett authored
    This commit makes sourcing spark in bash work properly and also removes the
    help function when sourced so as not to pollute the namespace.
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 26 deletions.
  1. +26 −26 spark
52 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
Something went wrong with that request. Please try again.