-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbashsh-0
executable file
·65 lines (55 loc) · 1.32 KB
/
bashsh-0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
set -o errexit
set -o nounset
if [[ "$0" = "${BASH_SOURCE[0]}" ]] ; then # '#!/usr/bin/env bashsh-0'
if [[ $# -eq 0 ]] ; then
echo 'ERROR: Bashsh must be run from a script.' >&2
echo >&2
echo 'Usage variants:' >&2
echo ' #!/usr/bin/env bashsh-0' >&2
echo 'or' >&2
echo ' source bashsh-0' >&2
exit 1
fi
DIR="$( cd "$( dirname "$1" )" && pwd )"
else # 'source bashsh-0'
# DIR="$( cd "$( dirname "${BASH_SOURCE[1]:-}" )" && pwd )"
DIR="$( cd "$( dirname "${BASH_SOURCE[1]}" )" && pwd )"
fi
# http://misc.flogisoft.com/bash/tip_colors_and_formatting
# http://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux#comment24883926_5947802
if [[ "$(uname -s)" = "Darwin" || "$(uname -s)" = "Linux" ]] ; then
bold='\033[1m'
else
# Make it a different color on Windows:
bold='\033[38;5;172m'
fi
normal='\033[0m'
function QUOTED() {
echo "$(printf "%q " "$@")"
}
function CMD_STR() {
ECHO "$@"
eval "$@"
}
function CMD() {
CMD_STR "$(QUOTED "$@")"
}
function ECHO() {
echo -ne "$bold" >&2
echo "$@" >&2
echo -ne "$normal" >&2
}
function MSG() {
ECHO "# $@"
}
function READ_P() {
ECHO -n "# $1"
shift
read "$@" >&2
}
if [[ "$0" = "${BASH_SOURCE[0]}" ]] ; then # '#!/usr/bin/env bashsh-0'
_program=$1
shift
. "$_program"
fi