@@ -14,56 +14,62 @@ basalt-package-init.main() {
14
14
local basalt_global_repo=" ${0%/* } "
15
15
basalt_global_repo=" ${basalt_global_repo%/* } " ; basalt_global_repo=" ${basalt_global_repo%/* } "
16
16
17
- cat << - EOF
17
+ cat << EOF
18
18
basalt.package-init() {
19
- # basalt variables
20
- export BASALT_GLOBAL_REPO="$basalt_global_repo "
21
- EOF
19
+ # basalt variables
20
+ export BASALT_GLOBAL_REPO="$basalt_global_repo "
21
+ EOF
22
+ cat << "EOF "
23
+ export BASALT_GLOBAL_DATA_DIR="${BASALT_GLOBAL_DATA_DIR:-"${XDG_DATA_HOME:-$HOME/.local/share}/basalt"}"
22
24
23
- cat << -"EOF "
24
- export BASALT_GLOBAL_DATA_DIR="${BASALT_GLOBAL_DATA_DIR:-"${XDG_DATA_HOME:-$HOME/.local/share}/basalt"}"
25
+ # basalt global and internal functions
26
+ source "$BASALT_GLOBAL_REPO/pkg/lib/public/basalt-load.sh"
27
+ source "$BASALT_GLOBAL_REPO/pkg/lib/public/basalt-package.sh"
25
28
26
- # basalt global and internal functions
27
- source "$BASALT_GLOBAL_REPO/pkg/lib/public/basalt-load.sh"
28
- source "$BASALT_GLOBAL_REPO/pkg/lib/public/basalt-package.sh"
29
+ if [ -z "${BASALT_PACKAGE_DIR:-}" ]; then
30
+ local __old_cd="$PWD"
29
31
30
- # TODO: this needs to be redone
31
- if [ -z "${BASALT_PACKAGE_DIR:-}" ]; then
32
- local __old_cd="$PWD"
33
- if [ -L "$0" ]; then
34
- local __file="$(readlink "$0")"
35
- if ! cd "${__file%/*}"; then
36
- printf '%s\n' "Error: basalt-package-init: Could not cd to target of '$0'"
37
- return 1
38
- fi
39
- fi
32
+ # Do not use "$0", since it won't work in some environments, such as Bats
33
+ local __basalt_file="${BASH_SOURCE[0]}"
34
+ if [ -L "$__basalt_file" ]; then
35
+ local __basalt_target="$(readlink "$__basalt_file")"
36
+ if ! cd "${__basalt_target%/*}"; then
37
+ printf '%s\n' "Error: basalt-package-init: Could not cd to '${__basalt_target%/*}'"
38
+ return 1
39
+ fi
40
+ else
41
+ if ! cd "${__basalt_file%/*}"; then
42
+ printf '%s\n' "Error: basalt-package-init: Could not cd to '${__basalt_file%/*}'"
43
+ return 1
44
+ fi
45
+ fi
40
46
41
- if ! BASALT_PACKAGE_DIR="$(
42
- while [ ! -f 'basalt.toml' ] && [ "$PWD" != / ]; do
43
- if ! cd ..; then
44
- return 1
45
- fi
46
- done
47
+ if ! BASALT_PACKAGE_DIR="$(
48
+ while [ ! -f 'basalt.toml' ] && [ "$PWD" != / ]; do
49
+ if ! cd ..; then
50
+ return 1
51
+ fi
52
+ done
47
53
48
- if [ "$PWD" = / ]; then
49
- return 1
50
- fi
54
+ if [ "$PWD" = / ]; then
55
+ return 1
56
+ fi
51
57
52
- printf '%s' "$PWD"
53
- )"; then
54
- printf '%s\n' "Error: basalt-package-init: Could not find basalt.toml"
55
- if ! cd "$__old_cd"; then
56
- printf '%s\n' "Error: basalt-package-init: Could not cd back to '$__old_cd'"
57
- return 1
58
- fi
59
- return 1
60
- fi
58
+ printf '%s' "$PWD"
59
+ )"; then
60
+ printf '%s\n' "Error: basalt-package-init: Could not find basalt.toml"
61
+ if ! cd "$__old_cd"; then
62
+ printf '%s\n' "Error: basalt-package-init: Could not cd back to '$__old_cd'"
63
+ return 1
64
+ fi
65
+ return 1
66
+ fi
61
67
62
- if ! cd "$__old_cd"; then
63
- printf '%s\n' "Error: basalt-package-init: Could not cd back to '$__old_cd'"
64
- return 1
65
- fi
66
- fi
68
+ if ! cd "$__old_cd"; then
69
+ printf '%s\n' "Error: basalt-package-init: Could not cd back to '$__old_cd'"
70
+ return 1
71
+ fi
72
+ fi
67
73
}
68
- EOF
74
+ EOF
69
75
}
0 commit comments