Skip to content

fix failing if check in autoload script - #1821

Merged
ljharb merged 1 commit into
nvm-sh:masterfrom
sidsakhadeo:fix-autload-script
May 26, 2018
Merged

ljharb merged 1 commit into
nvm-sh:masterfrom
sidsakhadeo:fix-autload-script

Conversation

@sidsakhadeo

Copy link
Copy Markdown

Fixes #1812

@ljharb
ljharb merged commit b81c120 into nvm-sh:master May 26, 2018
@sidsakhadeo

Copy link
Copy Markdown
Author

Hi @bjrbhre, as per the script

autoload -U add-zsh-hook
load-nvmrc() {
  local node_version="$(nvm version)" # gets default node version
  local nvmrc_path="$(nvm_find_nvmrc)" # gets path of .nvmrc in current dir

  if [ -n "$nvmrc_path" ]; then
    # following variable is assigned the node version listed in the .nvmrc, if installed
    # else it is assigned "N/A"
    local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") 
    if [ "$nvmrc_node_version" = "N/A" ]; then
      nvm install # when "N/A" it installs this new node version
    elif [ "$nvmrc_node_version" = "$node_version" ]; then
      nvm use # if already installed it will use this node version
    fi
  elif [ "$node_version" != "$(nvm version default)" ]; then
    echo "Reverting to nvm default version"
    nvm use default
  fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc

i think without removing the ! in the second check, it would never execute an nvm use, hence the change

@sidsakhadeo
sidsakhadeo deleted the fix-autload-script branch May 30, 2018 14:58
@ljharb ljharb mentioned this pull request May 30, 2018
@bjrbhre

bjrbhre commented Jun 19, 2018 •

Copy link
Copy Markdown

Hi @sidsakhadeo. Thanks for your comment and sorry for the delay in answering.

If [ "$nvmrc_node_version" = "$node_version" ] then you just don't need to execute nvm use because it means that you already use the version listed in nvmrc. You need to execute nvm use if they don't match. I do believe the ! is useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants