From 8b71861d06eea1a162fe3c0302089e60f70229c1 Mon Sep 17 00:00:00 2001 From: "Brian M. Jemilo II" Date: Mon, 9 Apr 2018 15:13:02 -0500 Subject: [PATCH] [Fix] `install.sh`: Detect profile with $BASH_VERSION and $ZSH_VERSION Using `$(basename "/$SHELL")` to detect the shell would also choose bash on mac --- install.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index db12c38..0c5f453 100755 --- a/install.sh +++ b/install.sh @@ -219,16 +219,14 @@ nvm_detect_profile() { local DETECTED_PROFILE DETECTED_PROFILE='' - local SHELLTYPE - SHELLTYPE="$(basename "/$SHELL")" - if [ "$SHELLTYPE" = "bash" ]; then + if [ -n "${BASH_VERSION-}" ]; then if [ -f "$HOME/.bashrc" ]; then DETECTED_PROFILE="$HOME/.bashrc" elif [ -f "$HOME/.bash_profile" ]; then DETECTED_PROFILE="$HOME/.bash_profile" fi - elif [ "$SHELLTYPE" = "zsh" ]; then + elif [ -n "${ZSH_VERSION-}" ]; then DETECTED_PROFILE="$HOME/.zshrc" fi @@ -330,8 +328,7 @@ nvm_do_install() { PROFILE_INSTALL_DIR="$(nvm_install_dir | command sed "s:^$HOME:\$HOME:")" SOURCE_STR="\\nexport NVM_DIR=\"${PROFILE_INSTALL_DIR}\"\\n[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\" # This loads nvm\\n" - ZSH_COMPLETION_STR='# Load compinit/compdef\n autoload -U compinit\n compinit' - + # shellcheck disable=SC2016 COMPLETION_STR='[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion\n' BASH_OR_ZSH=false @@ -360,7 +357,6 @@ nvm_do_install() { # shellcheck disable=SC2016 if ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then echo "=> Appending bash_completion source string to $NVM_PROFILE" - command printf "$ZSH_COMPLETION_STR" >> "$NVM_PROFILE" command printf "$COMPLETION_STR" >> "$NVM_PROFILE" else echo "=> bash_completion source string already in ${NVM_PROFILE}"