Giter Site home page Giter Site logo

fast-nvm-fish's Introduction

What is nvm?

nvm is a tool for managing multiple versions of node and npm.

What is fast-nvm-fish?

It's a utility that manipulates your PATH to include the desired version of node. Other solutions require parsing env's output and do other slow things. Before this, there was an extra second or two added to my shell startup time. With about 10 versions of node installed this script takes 50ms to run.

Alternatives

You can get even better performance, with a solution that works in fish/bash/zsh by using fnm.

Usage

nvm install 5
nvm use 5 # or e.g. 5.8 or 5.8.1

Install:

Requirements: you must have Fish 2.6.0 or newer.

First install nvm if you haven't already. You can check the nvm readme for a more up to data install command.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

Then install fast-nvm-fish:

curl -sSL https://raw.githubusercontent.com/brigand/fast-nvm-fish/master/nvm.fish > ~/.config/fish/functions/nvm.fish

Or using fisher:

fisher add brigand/fast-nvm-fish

The fish_user_paths universal variable must exist before running nvm commands. Run this once in your fish shell:

set -U fish_user_paths

To make it work on new shells you'll need to set a version in config.fish.

echo 'nvm use 7.2.1' >> ~/.config/fish/config.fish

If you have nvm installed anywhere other than ~/.nvm, set a global variable in your config.fish file before first invoking nvm use.

set -gx NVM_DIR ~/custom_path/nvm
nvm use 7.2.1

fast-nvm-fish's People

Contributors

blob42 avatar bradleyflood avatar brigand avatar cgsimmons avatar hilzu avatar nthapaliya avatar pgilad avatar proloser avatar rasmuswl avatar rmccue avatar sebdah avatar the-alchemist avatar tomsaleeba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fast-nvm-fish's Issues

Better version when loading the terminal

From the Readme:

To make it work on new shells you'll need to set a version in config.fish.

echo 'nvm use 7.2.1' >> ~/.config/fish/config.fish

I improved this as follows:

if test -e ./.nvmrc
    nvm use
else
    nvm use default
end

This will mimic the behaviour expected from nvm, i.e. it will use the default alias version. Except if there is a .nvmrc file in the current folder, then it will use that version.

Maybe we could update the readme accordingly?

Mention that nvm must also be installed

Hi 👋

I really like this tool, thank you, but the documentation could be much better. In particular, I think it would be useful to mention that nvm is still required for this tool to work.

I would also mention the set -U fish_user_paths command higher up in the document because it's the first thing that needs to be run.

Again, thank you.

Running with no args prints error

Steps:

  1. use fast-nvm-fish 2a5ad55
  2. run nvm (with no args)

Expected:
The help message for nvm is shown.

Actual:
The warning from this script is shown (not the issue here) and an error message from the test command:

nvm-fast: at least one argument is required
test: Missing argument at index 2

I think if you show that warning message, the script should halt because continuing without something the script states it needs is heading for failure.

Alternatively, don't worry about printing a warning and instead, set the default arg to --help and let the script continue. I'm a fan of this approach.

Errors on `nvm use` - `Unknown command 'string' etc.

I'm getting the below error from the latest nvm.fish function.

nvm use 9
fish: Unknown command 'string'
in command substitution
	called on line 0 of file ~/.config/fish/functions/nvm.fish

in function 'nvm-fast'
	called on line 44 of file ~/.config/fish/functions/nvm.fish
	with parameter list 'use 9'

in function 'nvm'
	called on standard input
	with parameter list 'use 9'

fish: Unknown command 'sed'
/usr/local/share/fish/functions/prompt_pwd.fish (line 2): 	echo $PWD | sed -e "s|^$realhome|~|" $args_pre -e 's-\([^/.]\)[^/]*/-\1/-g' $args_post
                                                          	            ^
in function 'prompt_pwd'
	called on line 6 of file /usr/local/share/fish/functions/fish_prompt.fish

in command substitution
	called on line 4 of file /usr/local/share/fish/functions/fish_prompt.fish

in function 'fish_prompt'
	called on standard input

in command substitution
	called on standard input

I wasn't getting this error until I updated my nvm.fish function today.

I've tried reinstalling everything, from iTerm2, nvm, and nvm-fast-fish. I've had to roll back a few commits on nvm.fish and everything works fine :) Looks like a bug has been introduced.

.nvmrc support for `nvm use`

when invoking nvm use with .nvmrc got the following error:

> nvm use                                                                         13:53:05
Array index out of bounds
~/.config/fish/functions/nvm.fish (line 9): 		set -l target_version $argv[2]
                                            		                            ^
in function 'nvm-fast'
	called on line 98 of file ~/.config/fish/functions/nvm.fish
	with parameter list 'use'

in function 'nvm'
	called on standard input
	with parameter list 'use'

No version installed for , run nvm install
Installed versions:
 - /Users/piotrek/.nvm/versions/node/v6.10.2
 - /Users/piotrek/.nvm/versions/node/v7.9.0
  • .nvmrc file contents
6.10.2

reference: https://github.com/creationix/nvm#nvmrc

`nvm use...` causes error "string match: Unknown option “-ev”"

fast-nvm-fish commit: 2a5ad55

Steps:

  1. install a version of Fish earlier than 2.6.0
  2. curl -sSL https://raw.githubusercontent.com/brigand/fast-nvm-fish/master/nvm.fish > ~/.config/fish/functions/nvm.fish
  3. set -U fish_user_paths
  4. Open a new shell
  5. nvm use 9

Expected:
Assuming I already have node 9 installed, nvm should select the installed version.

Actual:
An error is thrown:

string match: Unknown option “-ev”
~/.config/fish/functions/nvm.fish (line 2): string match -ev "$brigand_nvm_fish_path" $PATH
                                            ^
in command substitution
        called on line 0 of file ~/.config/fish/functions/nvm.fish

in function “nvm-fast”
        called on line 44 of file ~/.config/fish/functions/nvm.fish
        with parameter list “use 9”

in function “nvm”
        called on standard input
        with parameter list “use 9”


       string -- manipulate strings

   Synopsis
       string length [(-q | --quiet)] [STRING...]
       string sub [(-s | --start) START] [(-l | --length) LENGTH] [(-q | --quiet)]
                  [STRING...]
       string split [(-m | --max) MAX] [(-r | --right)] [(-q | --quiet)] SEP
                    [STRING...]
       string join [(-q | --quiet)] SEP [STRING...]
       string trim [(-l | --left)] [(-r | --right)] [(-c | --chars CHARS)]
                   [(-q | --quiet)] [STRING...]
       string escape [(-n | --no-quoted)] [STRING...]
       string match [(-a | --all)] [(-i | --ignore-case)] [(-r | --regex)]
                    [(-n | --index)] [(-q | --quiet)] [(-v | --invert)] PATTERN [STRING...]
       string replace [(-a | --all)] [(-i | --ignore-case)] [(-r | --regex)]
                      [(-q | --quiet)] PATTERN REPLACEMENT [STRING...]

string: Type “help string” for related documentation

Doesn't resolve aliases

Aliases such as stable, system, etc aren't resolved to the correct version. This appears to be due to the way versions are matched directly against directories.

For example:

$ nvm ls
->      v6.11.0
         v8.1.2
         system
default -> 6 (-> v6.11.0)
node -> stable (-> v8.1.2) (default)
stable -> 8.1 (-> v8.1.2) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> v6.11.0)
lts/argon -> v4.8.3 (-> N/A)
lts/boron -> v6.11.0

$ nvm current
v6.11.0

$ nvm use stable

$ nvm current
v6.11.0

This could be fixed by resolving using nvm ls $version instead:

$ nvm ls stable
         v8.1.2

(Appears to need processing to strip display characters, but otherwise should work.)

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.