From 4ac39e8b9b7e0185aa47067dd280274ab033e2a1 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Tue, 15 Jun 2021 10:02:34 -0300 Subject: [PATCH] Respect BIN_DIR in install script (#566) --- scripts/install | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index 3ff4e42..1b7ce0e 100755 --- a/scripts/install +++ b/scripts/install @@ -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"}" # ===================== @@ -217,7 +218,7 @@ get_shell() { export_path_cmd() { echo - echo ' export PATH="${PATH}:'"$BIN_DIR"'"' + echo ' export PATH="${PATH}:'"$1"'"' } append_to_file() { @@ -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)" @@ -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" @@ -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 }