-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh-dynconf-init
More file actions
executable file
·49 lines (38 loc) · 2.49 KB
/
ssh-dynconf-init
File metadata and controls
executable file
·49 lines (38 loc) · 2.49 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
# !/usr/bin/env bash
if [ -n "${__ssh_dynconf_included__}" ]; then return 0; fi
export __ssh_dynconf_included__=true
# =============================== > Settings < =============================== #
if [ -z "${SSH_DYNCONF_DIR}" ]; then
if [ -n "$BASH_VERSION" ]; then
current_file="${BASH_SOURCE[0]}"
elif [ -n "$ZSH_VERSION" ]; then
current_file="${(%):-%N}"
fi
SSH_DYNCONF_DIR="$(dirname $(readlink -f "${current_file}"))"
fi
# ────────────────────────────────── <end> ─────────────────────────────────── #
# ========================== > Source submodules < =========================== #
source ${SSH_DYNCONF_DIR}/submodules/bash-aux/bash-aux-init
# ────────────────────────────────── <end> ─────────────────────────────────── #
# =================== > Save currently defined functions < =================== #
# To exclude them from exporting
functions_not_export="$(declare -F)"
# ────────────────────────────────── <end> ─────────────────────────────────── #
# ============================= > Source files < ============================= #
source ${SSH_DYNCONF_DIR}/functions/ssh_available_hosts
source ${SSH_DYNCONF_DIR}/functions/ssh_host_available
source ${SSH_DYNCONF_DIR}/functions/ssh_host_name
source ${SSH_DYNCONF_DIR}/functions/ssh_config_update
# ────────────────────────────────── <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> ─────────────────────────────────── #