-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash-aux-init
48 lines (41 loc) · 2.37 KB
/
bash-aux-init
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
#!/usr/bin/env bash
if [ -n "${__bash_aux_included__}" ]; then return 0; fi
export __bash_aux_included__=true
if [ -z "${BASH_AUX_DIR}" ]; then
current_file=
if [ -n "$BASH_VERSION" ]; then
current_file="${BASH_SOURCE[0]}"
elif [ -n "$ZSH_VERSION" ]; then
current_file="${(%):-%x}"
fi
BASH_AUX_DIR="$(dirname $(readlink -f "${current_file}"))"
fi
# ========================== > Source submodules < =========================== #
source ${BASH_AUX_DIR}/submodules/bash-doc/bash-doc-init
# ────────────────────────────────── <end> ─────────────────────────────────── #
# =================== > Save currently defined functions < =================== #
# To exclude them from exporting
functions_not_export="$(declare -F)"
# ────────────────────────────────── <end> ─────────────────────────────────── #
# ===================== > Source and export functions < ====================== #
source ${BASH_AUX_DIR}/functions/bash_aux_log
source ${BASH_AUX_DIR}/functions/check_dependencies
source ${BASH_AUX_DIR}/functions/check_dependency
source ${BASH_AUX_DIR}/functions/current_file
source ${BASH_AUX_DIR}/functions/make_file_path
source ${BASH_AUX_DIR}/functions/normalize_path
source ${BASH_AUX_DIR}/functions/read_from_file
source ${BASH_AUX_DIR}/functions/read_non_blocking
# ────────────────────────────────── <end> ─────────────────────────────────── #
# ================== > Export all newly defined functions < ================== #
readarray -t functions <<<"$(declare -F)"
functions_export="$(
for function in "${functions[@]}"; do
if [[ ! $functions_not_export =~ $function ]];then
echo "$function" |
perl -p0e "s/declare\s+-f\s+(.*)\s*$/export -f \${1}\n/gi"
fi
done
)"
eval "${functions_export}"
# ────────────────────────────────── <end> ─────────────────────────────────── #