Skip to content

Commit

Permalink
Respect BIN_DIR in install script (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Jun 15, 2021
1 parent 4c9583b commit 4ac39e8
Showing 1 changed file with 30 additions and 6 deletions.
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

0 comments on commit 4ac39e8

Please sign in to comment.