Skip to content

Commit 11e6fdb

Browse files
committed
fix: install script auto-adds bindir to PATH
- Default install dir: $GOPATH/bin (if Go installed) or ~/.local/bin - Detects user shell (zsh, bash, fish) and appends PATH to correct rc file - Idempotent: skips if PATH line already exists in profile - Based on OpenAI Codex installer pattern
1 parent d909845 commit 11e6fdb

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

install.sh

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ EOF
1717
}
1818

1919
parse_args() {
20-
if go env GOPATH >/dev/null 2>&1; then
21-
DEFAULT_BINDIR=$(go env GOPATH)/bin
20+
if [ -n "$GOPATH" ] && [ -d "$GOPATH/bin" ]; then
21+
DEFAULT_BINDIR="$GOPATH/bin"
22+
elif [ -n "$HOME" ]; then
23+
DEFAULT_BINDIR="$HOME/.local/bin"
2224
else
2325
DEFAULT_BINDIR=./bin
2426
fi
@@ -36,6 +38,42 @@ parse_args() {
3638
TAG=$1
3739
}
3840

41+
add_to_path() {
42+
# Check if BINDIR is already in PATH
43+
case ":$PATH:" in
44+
*":$BINDIR:"*)
45+
log_info "Directory ${BINDIR} is already in PATH"
46+
return
47+
;;
48+
esac
49+
50+
# Detect the user's shell config file
51+
profile=""
52+
case "${SHELL:-}" in
53+
*/zsh) profile="$HOME/.zshrc" ;;
54+
*/bash) profile="$HOME/.bashrc" ;;
55+
*/fish) return ;; # fish handles PATH differently
56+
*) profile="$HOME/.profile" ;;
57+
esac
58+
59+
# Check if it's already configured (idempotent)
60+
path_line="export PATH=\"${BINDIR}:\$PATH\""
61+
if [ -f "$profile" ] && grep -F "$path_line" "$profile" >/dev/null 2>&1; then
62+
log_info "PATH already configured in ${profile}"
63+
log_info "Run: source ${profile} (or open a new terminal)"
64+
return
65+
fi
66+
67+
# Append to shell config
68+
{
69+
printf '\n# Added by pathdigest installer\n'
70+
printf '%s\n' "$path_line"
71+
} >>"$profile"
72+
73+
log_info "Added ${BINDIR} to PATH in ${profile}"
74+
log_info "Run: source ${profile} (or open a new terminal)"
75+
}
76+
3977
execute() {
4078
tmpdir=$(mktemp -d)
4179
log_debug "Downloading files to ${tmpdir}"
@@ -67,6 +105,8 @@ execute() {
67105
log_info "Installed ${TARGET_BIN_PATH}"
68106

69107
rm -rf "${tmpdir}"
108+
109+
add_to_path
70110
}
71111

72112
get_binaries_info() {

0 commit comments

Comments
 (0)