generated from LoveDuckie/python-tool-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared_functions.sh
executable file
·113 lines (92 loc) · 2.42 KB
/
shared_functions.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
<<EOF
Shell Scripts \ Shared Functions
A collection of shared and reusable functions.
EOF
CURRENT_SCRIPT_DIRECTORY=${CURRENT_SCRIPT_DIRECTORY:-$(dirname $(realpath ${BASH_SOURCE[0]:-${(%):-%x}}))}
export CURRENT_SCRIPT_FILENAME=${CURRENT_SCRIPT_FILENAME:-$(basename ${BASH_SOURCE[0]:-${(%):-%x}})}
export CURRENT_SCRIPT_FILENAME_BASE=${CURRENT_SCRIPT_FILENAME%.*}
export PROJECT_NAME="search-pathfinding"
unset -f write_header
unset -f write_header_sub
unset -f write_info
unset -f write_warning
unset -f write_error
unset -f write_debug
unset -f write_response
unset -f write_success
unset -f is_command_available
is_macos() {
if [[ "$(uname)" == "Darwin" ]]; then
return 0 # True - running on macOS
else
return 1 # False - not running on macOS
fi
}
is_command_available() {
if [[ "$(command -v $1)" != "" ]] && [[ "$(type -t $1)" != "" ]]; then
return 0
fi
return 1
}
write_header_sub() {
if [ ! -z "$CURRENT_SCRIPT_FILENAME" ]; then
echo ""
write_info "*** SCRIPT: $(echo \"${CURRENT_SCRIPT_FILENAME%.*}\" | awk '{print toupper($0)}')"
echo ""
fi
return 0
}
write_header() {
if [[ "$OPTIONS_LOG_SHOW_HEADER" == "1" ]] && [ -z "$HEADER_OUTPUT" ] && [ -e "$SHARED_SCRIPTS_PATH_ENV/script-header" ]; then
if [ ! -z "$HEADER_OUTPUT_LOLCAT" ]; then
cat $SHARED_SCRIPTS_PATH_ENV/script-header | lolcat
else
echo -e "\033[1;37m$(cat $SHARED_SCRIPTS_PATH_ENV/script-header)\033[0m"
fi
fi
export HEADER_OUTPUT=1
write_header_sub
return 0
}
write_info() {
MSG=$2
echo -e "\033[1;36m $1\033[0m \033[0;37m${MSG}\033[0m" 1>&2
}
write_success() {
MSG=$2
echo -e "\033[1;32m $1\033[0m \033[0;37m${MSG}\033[0m" 1>&2
}
write_error() {
MSG=$2
echo -e "\033[1;31m $1\033[0m \033[0;37m${MSG}\033[0m" 1>&2
}
write_warning() {
MSG=$2
echo -e "\033[1;33m $1\033[0m \033[0;37m${MSG}\033[0m" 1>&2
}
write_debug() {
if [ -z "$OPTIONS_LOG_ENABLE_DEBUG" ]; then
return 1
fi
MSG=$2
echo -e "\e[1;33m$1\e[0m \e[0;37m${MSG}\e[0m" 1>&2
return 0
}
write_response() {
if [ $? -ne 0 ]; then
write_error "error" "$2"
return 1
fi
write_success "success" "$2"
return 0
}
export -f write_header
export -f write_header_sub
export -f write_info
export -f write_warning
export -f write_error
export -f write_debug
export -f write_response
export -f write_success
export -f is_command_available