Skip to content

Commit 48c3f2f

Browse files
committed
fix: No longer use short circuiting operators for util.init_global
This also makes changes so that links don't get created for directories that do not exist
1 parent e7553b1 commit 48c3f2f

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

pkg/lib/util/util.sh

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,30 @@ util.init_global() {
3434
print.die "Either 'BASALT_GLOBAL_REPO' or 'BASALT_GLOBAL_DATA_DIR' is empty. Did you forget to run add 'basalt init <shell>' in your shell configuration?"
3535
fi
3636

37-
# TODO
38-
[ -d "$BASALT_GLOBAL_REPO" ] || mkdir -p "$BASALT_GLOBAL_REPO"
39-
[ -d "$BASALT_GLOBAL_DATA_DIR/global" ] || mkdir -p "$BASALT_GLOBAL_DATA_DIR/global"
40-
[ -d "$BASALT_GLOBAL_DATA_DIR/store" ] || mkdir -p "$BASALT_GLOBAL_DATA_DIR/store"
41-
[ -f "$BASALT_GLOBAL_DATA_DIR/global/dependencies" ] || touch "$BASALT_GLOBAL_DATA_DIR/global/dependencies"
42-
43-
[ -L "$BASALT_GLOBAL_DATA_DIR/global/bin" ] || ln -sf "$BASALT_GLOBAL_DATA_DIR/global/.basalt/packages/bin" "$BASALT_GLOBAL_DATA_DIR/global/bin"
44-
[ -L "$BASALT_GLOBAL_DATA_DIR/global/completion" ] || ln -sf "$BASALT_GLOBAL_DATA_DIR/global/.basalt/packages/completion" "$BASALT_GLOBAL_DATA_DIR/global/completion"
45-
[ -L "$BASALT_GLOBAL_DATA_DIR/global/man" ] || ln -sf "$BASALT_GLOBAL_DATA_DIR/global/.basalt/packages/man" "$BASALT_GLOBAL_DATA_DIR/global/man"
37+
if [ ! -d "$BASALT_GLOBAL_REPO" ]; then
38+
mkdir -p "$BASALT_GLOBAL_REPO"
39+
fi
40+
if [ ! -d "$BASALT_GLOBAL_DATA_DIR/global" ]; then
41+
mkdir -p "$BASALT_GLOBAL_DATA_DIR/global"
42+
fi
43+
if [ ! -d "$BASALT_GLOBAL_DATA_DIR/store" ]; then
44+
mkdir -p "$BASALT_GLOBAL_DATA_DIR/store"
45+
fi
46+
if [ ! -f "$BASALT_GLOBAL_DATA_DIR/global/dependencies" ]; then
47+
"$BASALT_GLOBAL_DATA_DIR/global/dependencies"
48+
fi
49+
50+
# Note that I would prefer to check the existence of the target directory as well, but that would mean if the user installs
51+
# a package that creates for example a 'completion' directory, it would not show up until 'basalt' is executed again
52+
if [ ! -L "$BASALT_GLOBAL_DATA_DIR/global/bin" ]; then
53+
ln -sf "$BASALT_GLOBAL_DATA_DIR/global/.basalt/packages/bin" "$BASALT_GLOBAL_DATA_DIR/global/bin"
54+
fi
55+
if [ ! -L "$BASALT_GLOBAL_DATA_DIR/global/completion" ]; then
56+
ln -sf "$BASALT_GLOBAL_DATA_DIR/global/.basalt/packages/completion" "$BASALT_GLOBAL_DATA_DIR/global/completion"
57+
fi
58+
if [ ! -L "$BASALT_GLOBAL_DATA_DIR/global/man" ]; then
59+
ln -sf "$BASALT_GLOBAL_DATA_DIR/global/.basalt/packages/man" "$BASALT_GLOBAL_DATA_DIR/global/man"
60+
fi
4661
}
4762

4863
util.init_always() {

0 commit comments

Comments
 (0)