Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect BIN_DIR in install script #566

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ fi
# paths
# =====================

export BIN_DIR="${BIN_DIR:-"${HOME}/.cargo/bin"}"
export CARGO_DEFAULT_BIN="${HOME}/.cargo/bin"
export BIN_DIR="${BIN_DIR:-"$CARGO_DEFAULT_BIN"}"


# =====================
Expand Down Expand Up @@ -217,7 +218,7 @@ get_shell() {

export_path_cmd() {
echo
echo ' export PATH="${PATH}:'"$BIN_DIR"'"'
echo ' export PATH="${PATH}:'"$1"'"'
}

append_to_file() {
Expand All @@ -228,6 +229,19 @@ append_to_file() {
fi
}

get_navi_bin_path() {
local file="${BIN_DIR}/navi"
if [ -f "$file" ]; then
echo "$file"
return 0
fi
file="${CARGO_DEFAULT_BIN}/navi"
if [ -f "$file" ]; then
echo "$file"
return 0
fi
}

install_navi() {
local -r target="$(get_target)"

Expand All @@ -250,15 +264,25 @@ install_navi() {

fi

hash -r 2>/dev/null || true

local navi_bin_path="$(which navi || get_navi_bin_path)"
ln -s "$navi_bin_path" "${BIN_DIR}/navi" &>/dev/null || true
if [ -f "${BIN_DIR}/navi" ]; then
navi_bin_path="${BIN_DIR}/navi"
fi

local -r navi_bin_dir="$(dirname "$navi_bin_path")"

echoerr
log::success "Finished"
log::success "navi is now available at ${BIN_DIR}/navi"
log::success "navi is now available at ${navi_bin_path}"
echoerr

if echo "$PATH" | grep -q "$BIN_DIR"; then
if echo "$PATH" | grep -q "$navi_bin_path"; then
:
else
local -r cmd="$(export_path_cmd)"
local -r cmd="$(export_path_cmd "$navi_bin_path")"
append_to_file "${HOME}/.bashrc" "$cmd"
append_to_file "${ZDOTDIR:-"$HOME"}/.zshrc" "$cmd"
append_to_file "${HOME}/.fishrc" "$cmd"
Expand All @@ -268,7 +292,7 @@ install_navi() {
echo
log::note "Check https://github.com/denisidoro/navi for more info"

export PATH="${PATH}:${BIN_DIR}"
export PATH="${PATH}:${navi_bin_path}"

return 0
}
Expand Down