Giter Site home page Giter Site logo

fish-nvm's Introduction

fish-nvm

nvm wrapper for fish-shell.

Install

With fisher

fisher add FabioAntunes/fish-nvm

With oh-my-fish

omf install https://github.com/FabioAntunes/fish-nvm
omf install https://github.com/edc/bass

Make sure you have NVM installed first.

fish-nvm depends on bass

Usage

nvm install 6.11.1
nvm alias default 6.11.1

How it works

The way this plugin works is delaying sourcing nvm, until we really need it. That way we don't have those annoying 1/2 seconds of delay every time we open a new terminal window/tab.

By delaying the sourcing of nvm YOUR NODE BINARIES WON'T BE LOADED until you source nvm or run one of the following alias. If you want to source nvm every single time you open a terminal just use bass

fish nvm example

There are a couple of alias already created. They will source NVM whenever you call them:

  • npm
  • yarn
  • node
  • nvm
  • npx

What this means is that if you depend on other node global packages, let's say gulp, if you try to run gulp in a fresh window/tab you will get something like Command unknown. One way to solve this is running nvm use default, or any of the alias before using the command gulp.

Since that's far from great, especially if you depend a lot on these global packages you can easily create your own function inside ~/.config/fish/functions, so for gulp would be something like this:

function gulp -d "gulp task manager" -w gulp
  __nvm_run "gulp" $argv
end

To simplify this process there's an helper function on fish-nvm just run nvm_alias_function name, you can pass multiple packages names, separated by spaces:

nvm_alias_function gulp webpack grunt

fish nvm example

This will create 3 functions on your functions folder ~/.config/fish/functions

Another common scenario is if you need to have the binary of the node or package available. For example if you are vim user, some plugins need access to the node binary. Since we only source nvm when we use one of the alias, you will probably get an error saying that node isn't available.

For example to create a binary for node we could create a file under /usr/local/bin

touch /usr/local/bin/node

Open that file on your editor and paste the following:

#! /usr/bin/env fish

__nvm_run "node" $argv

Make that file executable:

chmod +x /usr/local/bin/node

Test it

which node

To simplify this process there's another helper function nvm_alias_command

If you run nvm_alias_command without any arguments it will create the alias binaries provided by default by fish-nvm: npm, node, npx, yarn

fish nvm example

To create additional ones after running the first time without args, just pass them as arguments separated by spaces

nvm_alias_command eslint prettier

The default output path is /urs/local/bin, if you get an error message due to permissions, try running with sudo permissions:

sudo fish nvm_alias_command eslint prettier

To change the default output folder just set a global variable:

set -g nvm_alias_output /other/path

Please read these Notes:

Sometimes it might happen NVM is already sourced, with the wrong version, or not respecting your default version. Check your ~/.profile or ~/.bashrc or ~/.bash_profile. If that's the case, just remove the line that sources NVM.

Make sure you set a default node version or create a .nvmrc file on your working directory. fish-nvm will try to use the .nvmrc version specified, if the file exists, if there's no file it will try to use the default version.

If you don't use the .nvmrc file or if you don't set a default version, you will have to run nvm use node-version every time you open a new terminal and want to use node or npm

If you have a custom $NVM_DIR, please add the following line to your ~/.config/fish/config.fish, replacing the path accordingly:

set -gx NVM_DIR /path/to/nvm

Also, if you have a custom installation path but still set $NVM_DIR to default path. For example this could happen if you install NVM using brew, which would install nvm into: /usr/local/Cellar/nvm/%nvm_version%/nvm.sh

If that is the case you add the following line to your ~/.config/fish/config.fish, replacing the path accordingly:

set -gx nvm_prefix /path/to/nvm

NOTE:

DO NOT use a trailing slash in NVM_DIR variable. Adding it will cause error: nvm is not compatible with the npm config "prefix" option

Other

Check out also fnm a pure fish node version manager with automatic version switching.

License

fish-nvm is MIT licensed.

fish-nvm's People

Contributors

fabioantunes avatar schovi avatar pgilad avatar nathanjang avatar jorgebucaran avatar kvervo avatar romulof avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.