-
Notifications
You must be signed in to change notification settings - Fork 1
/
skeleton.sh
executable file
·62 lines (49 loc) · 1.58 KB
/
skeleton.sh
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
#!/usr/bin/env bash
__skeleton_main() {
local SH_SOURCE_FILE SH_SOURCE_DIR SH_SOURCE_FILE_ESCAPED
if [ -n "$ZSH_VERSION" ]; then
SH_SOURCE_FILE=${(%):-%x}
elif [ -n "$BASH_VERSION" ]; then
SH_SOURCE_FILE=${BASH_SOURCE[0]}
fi
while [[ -L "$SH_SOURCE_FILE" ]]; do
SH_SOURCE_FILE=$(readlink "$SH_SOURCE_FILE")
done
SH_SOURCE_DIR=$(dirname "$SH_SOURCE_FILE")
SH_SOURCE_DIR=`cd "$SH_SOURCE_DIR" >/dev/null; pwd`
SH_SOURCE_FILE=$(basename "$SH_SOURCE_FILE")
SH_SOURCE_FILE_ESCAPED=${SH_SOURCE_FILE// /_}
# SH_SOURCE_DIR is a full path to the location of this script
eval "$(cat <<EOF
__get_${SH_SOURCE_FILE_ESCAPED}_dir() {
echo $SH_SOURCE_DIR
}
__get_${SH_SOURCE_FILE_ESCAPED}_file() {
echo $SH_SOURCE_FILE
}
EOF
)"
local SH_COLOR_DEFS
if [[ -e "$SH_SOURCE_DIR/configure_colors" ]]; then
SH_COLOR_DEFS=`cat "$SH_SOURCE_DIR/configure_colors"`
fi
local SH_OS_DEFS
if [[ -e "$SH_SOURCE_DIR/configure_os" ]]; then
SH_OS_DEFS=`cat "$SH_SOURCE_DIR/configure_os"`
fi
eval "$(cat <<EOF
__sh_color_definitions() {
echo "$SH_COLOR_DEFS"
}
__sh_os_definitions() {
echo "$SH_OS_DEFS"
}
EOF
)"
eval "$(__sh_color_definitions)"
eval "$(__sh_os_definitions)"
echo -e 'Script path : '$COLOR_GREEN$(__get_${SH_SOURCE_FILE_ESCAPED}_dir)$COLOR_NONE
echo -e 'Script name : '$COLOR_GREEN$(__get_${SH_SOURCE_FILE_ESCAPED}_file)$COLOR_NONE
}
__skeleton_main "$@"
unset -f __skeleton_main