Skip to content

Commit 8faddf9

Browse files
committed
Merge pull request holman#56 from zsprackett/source_friendly
Fix it so that sourcing works properly
2 parents 643bbdc + 1912376 commit 8faddf9

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

spark

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@
2424
# spark -h
2525
# # => Prints the spark help text.
2626

27-
# Prints the help text for spark.
28-
help()
29-
{
30-
cat <<EOF
31-
32-
USAGE:
33-
spark [-h] VALUE,...
34-
35-
EXAMPLES:
36-
spark 1 5 22 13 53
37-
▁▁▃▂█
38-
spark 0,30,55,80,33,150
39-
▁▂▃▄▂█
40-
echo 9 13 5 17 1 | spark
41-
▄▆▂█▁
42-
EOF
43-
}
44-
4527
# Generates sparklines.
4628
#
4729
# $1 - The data we'd like to graph.
@@ -77,13 +59,31 @@ spark()
7759
}
7860

7961
# If we're being sourced, don't worry about such things
80-
[[ ${#BASH_SOURCE[@]} -eq 1 ]] || return
62+
if [ "$BASH_SOURCE" == "$0" ]; then
63+
# Prints the help text for spark.
64+
help()
65+
{
66+
cat <<EOF
8167
82-
# show help for no arguments if stdin is a terminal
83-
if { [ -z "$1" ] && [ -t 0 ] ; } || [ "$1" == '-h' ]
84-
then
85-
help
86-
exit
87-
fi
68+
USAGE:
69+
spark [-h] VALUE,...
70+
71+
EXAMPLES:
72+
spark 1 5 22 13 53
73+
▁▁▃▂█
74+
spark 0,30,55,80,33,150
75+
▁▂▃▄▂█
76+
echo 9 13 5 17 1 | spark
77+
▄▆▂█▁
78+
EOF
79+
}
8880

89-
spark ${@:-`cat`}
81+
# show help for no arguments if stdin is a terminal
82+
if { [ -z "$1" ] && [ -t 0 ] ; } || [ "$1" == '-h' ]
83+
then
84+
help
85+
exit
86+
fi
87+
88+
spark ${@:-`cat`}
89+
fi

0 commit comments

Comments
 (0)