-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlcl-utilities.plugin.bash
47 lines (41 loc) · 1.54 KB
/
sqlcl-utilities.plugin.bash
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
# shellcheck shell=bash
function main() {
function getCanonicalPath() {
########################################################################
# getCanonicalPath
#
# Return a path that is both absolute and does not contain any
# symbolic links. Always returns without a trailing slash.
#
# The first parameter is the path to canonicalize
#
# canonicalPath="$(getCanonicalPath "${somePath}")"
########################################################################
local target="${1}"
if [ -d "${target}" ]; then
# dir
(cd "${target}" || exit; pwd -P)
elif [ -f "${target}" ]; then
# file
if [[ "${target}" = /* ]]; then
# Absolute file path
(cd "$(dirname "${target}")" || exit; printf -- '%s/%s\n' "$(pwd -P)" "$(basename "${target}")")
elif [[ "${target}" == */* ]]; then
# Relative file with path
printf -- '%s\n' "$(cd "${target%/*}" || exit; pwd -P)/${target##*/}"
else
# Relative file without path
printf -- '%s\n' "$(pwd -P)/${target}"
fi
fi
} # getCanonicalPath
local scriptPath
local binDirectory
scriptPath="$(getCanonicalPath "$(dirname -- "${BASH_SOURCE[0]}")")"
binDirectory="${scriptPath}/bin"
for file in "${binDirectory}"/*.sh; do
# shellcheck source=bin/*
source "${file}"
done
} # main
main "$@"