Skip to content

Commit fb2fc38

Browse files
committed
fix: resolve symlinks in bashclaw entry point for correct BASHCLAW_ROOT
When bashclaw is invoked via a symlink (e.g. ~/.local/bin/bashclaw -> ~/.bashclaw/bin/bashclaw), BASH_SOURCE[0] resolves to the symlink location, causing BASHCLAW_ROOT to point at the wrong directory and all lib/*.sh sources to fail. Add _bashclaw_resolve_root() that follows symlink chains using readlink (without -f, compatible with macOS) to find the real script location before deriving BASHCLAW_ROOT.
1 parent 4151991 commit fb2fc38

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

bashclaw

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@
22
set -euo pipefail
33

44
BASHCLAW_VERSION="1.0.0"
5-
BASHCLAW_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
6+
# Resolve symlinks to find the real script location
7+
_bashclaw_resolve_root() {
8+
local source="${BASH_SOURCE[0]}"
9+
while [[ -L "$source" ]]; do
10+
local dir
11+
dir="$(cd "$(dirname "$source")" && pwd)"
12+
source="$(readlink "$source")"
13+
# Resolve relative symlink
14+
[[ "$source" != /* ]] && source="$dir/$source"
15+
done
16+
cd "$(dirname "$source")" && pwd
17+
}
18+
BASHCLAW_ROOT="$(_bashclaw_resolve_root)"
19+
unset -f _bashclaw_resolve_root
620
BASHCLAW_STATE_DIR="${BASHCLAW_STATE_DIR:-${HOME}/.bashclaw}"
721

822
export BASHCLAW_VERSION BASHCLAW_ROOT BASHCLAW_STATE_DIR

0 commit comments

Comments
 (0)