Skip to content

Instantly share code, notes, and snippets.

@fabiendem
Last active April 24, 2020 10:17
Show Gist options
  • Save fabiendem/db57d25671a95d2e8ac902cbe184eaa2 to your computer and use it in GitHub Desktop.
Save fabiendem/db57d25671a95d2e8ac902cbe184eaa2 to your computer and use it in GitHub Desktop.
Check nvm - Fish shell [:fish:]

Set node version when entering a folder using Fish shell 🐟

Copied from https://gist.github.com/eugenet8k/535bf3c51d1fc7c31cb8784e55d4dae4.
I have tweaked a bit the console logs.

Add to ~/.config/fish/config.fish:

function __check_nvm --on-variable PWD --description 'Checking nvm'
  if test -f .nvmrc
    echo ".nvmrc file detected, will set node version"
    set node_version (nvm version)
    set nvmrc_node_version (nvm version (cat .nvmrc))

    if [ $nvmrc_node_version = "N/A" ]
      nvm install
    else if [ $nvmrc_node_version != $node_version ]
      nvm use
    else
      echo "Correct node version already in use"
    end
  end
end

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