-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.shellscriptsrc
More file actions
53 lines (47 loc) · 1.57 KB
/
.shellscriptsrc
File metadata and controls
53 lines (47 loc) · 1.57 KB
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
#!/bin/bash
: # This script is to be sourced
: ##########################################################
: ##### Lookup BFD Repository Directory
command_exists() { command -v "$@" >/dev/null 2>&1; }
LC_ALL=C
export LC_ALL
: # by using a HEREDOC, we are disabling shellcheck and shfmt
set +e
read -r -d '' LOOKUP_SHELL_FUNCTION <<-'EOF'
lookup_shell() {
export whichshell
case ${ZSH_VERSION:-} in *.*) { whichshell=zsh;return;};;esac
case ${BASH_VERSION:-} in *.*) { whichshell=bash;return;};;esac
case "$VERSION" in *zsh*) { whichshell=zsh;return;};;esac
case "$SH_VERSION" in *PD*) { whichshell=sh;return;};;esac
case "$KSH_VERSION" in *PD*|*MIRBSD*) { whichshell=ksh;return;};;esac
}
EOF
set -e
eval "${LOOKUP_SHELL_FUNCTION}"
lookup_shell
if [[ -z ${BFD_REPOSITORY:-} ]]; then
set +e
read -r -d '' GET_LIB_DIR_IN_ZSH <<-'EOF'
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
0="${${(M)0:#/*}:-$PWD/$0}"
BFD_REPOSITORY="${0:a:h}"
BFD_REPOSITORY="$(cd "${BFD_REPOSITORY}" > /dev/null 2>&1 && pwd -P)"
EOF
set -e
# shellcheck enable=all
if command_exists zsh && [[ ${whichshell} == "zsh" ]]; then
# We are running in zsh
eval "${GET_LIB_DIR_IN_ZSH}"
else
# we are running in bash/sh
BFD_REPOSITORY="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -P)"
fi
fi
# End Lookup BFD Repository Directory
##########################################################
bash_or_zsh() {
{ [[ ${whichshell} == "zsh" ]] && echo "zsh"; } || echo "bash"
}
: "${SCRIPTS_LIB_DIR:=${BFD_REPOSITORY}/lib}"
eval "$(source "${SCRIPTS_LIB_DIR}/bootstrap.sh")"