├── .fish-install-homebrew.sh
├── .fish-install-source.sh
├── .github
└── workflows
│ └── test.yml
├── .nvm-install-homebrew.sh
├── .nvm-install-official.sh
├── .omf-install.sh
├── .plugin-install.sh
├── LICENSE
├── README.md
├── bundle
├── completions
└── nvm.fish
├── functions
└── nvm.fish
├── init.fish
└── test
├── bootstrap.fish
└── cases
├── 100_initialise_environment.fish
├── 101_display_nvm_help.fish
├── 102_display_current_node_version.fish
├── 103_list_node_versions.fish
└── 104_switch_node_versions.fish
/.fish-install-homebrew.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | brew update
4 | brew install fish
5 |
--------------------------------------------------------------------------------
/.fish-install-source.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -euo pipefail
4 |
5 | if test ! -d "${HOME}/fish-${FISH_RELEASE}"; then
6 | cd ${HOME}
7 | wget "https://github.com/fish-shell/fish-shell/releases/download/${FISH_RELEASE}/fish-${FISH_RELEASE}.tar.gz"
8 | tar -xzf "fish-${FISH_RELEASE}.tar.gz"
9 | rm "fish-${FISH_RELEASE}.tar.gz"
10 | cd "fish-${FISH_RELEASE}"
11 | cmake .
12 | make
13 | sudo make install
14 | else
15 | cd "${HOME}/fish-${FISH_RELEASE}"
16 | sudo make install
17 | echo Using cached fish install
18 | fi
19 |
20 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: "E2E Test"
2 |
3 | on: [pull_request]
4 |
5 | jobs:
6 | test:
7 | name: ${{ matrix.os }}, Fish ${{ matrix.fish }}, NVM ${{ matrix.nvm }}
8 | runs-on: ${{ matrix.os }}
9 | env:
10 | FISH_RELEASE: "3.1.0"
11 | OMF_INSTALLER: "https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install"
12 | NVM_INSTALLER: "https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh"
13 |
14 | strategy:
15 | matrix:
16 | fish: [homebrew, source]
17 | nvm: [homebrew, official]
18 | os: [ubuntu-latest, macOS-latest]
19 | exclude:
20 | - fish: homebrew
21 | nvm: homebrew
22 | os: ubuntu-latest
23 |
24 | - fish: source
25 | nvm: homebrew
26 | os: ubuntu-latest
27 |
28 | - fish: homebrew
29 | nvm: official
30 | os: ubuntu-latest
31 |
32 | steps:
33 | - name: Checkout code
34 | uses: actions/checkout@v1
35 |
36 | - name: Install system dependecies
37 | if: matrix.os == 'ubuntu-latest'
38 | run: |
39 | sudo apt-get update
40 | sudo apt-get install -y gettext libncurses5-dev libncursesw5-dev
41 |
42 | - name: Cache compiled Fish
43 | uses: actions/cache@v1
44 | if: matrix.fish == 'source'
45 | with:
46 | path: ~/fish-${{ env.FISH_RELEASE }}
47 | key: cache-${{ runner.os }}-fish-${{ env.FISH_RELEASE }}-nvm-${{ matrix.nvm }}-${{ hashFiles('.fish-install-source.sh') }}
48 |
49 | - name: Setup environment
50 | run: |
51 | ./.fish-install-${{ matrix.fish }}.sh
52 | ./.nvm-install-${{ matrix.nvm }}.sh
53 | ./.omf-install.sh
54 | ./.plugin-install.sh
55 |
56 | - name: Run tests
57 | run: |
58 | fish test/bootstrap.fish
59 |
--------------------------------------------------------------------------------
/.nvm-install-homebrew.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | brew update
4 | brew install nvm
5 |
6 | # Homebrew's Caveats
7 |
8 | # Please note that upstream has asked us to make explicit managing
9 | # nvm via Homebrew is unsupported by them and you should check any
10 | # problems against the standard nvm install method prior to reporting.
11 |
12 | # You should create NVM's working directory if it doesn't exist:
13 |
14 | mkdir ~/.nvm
15 |
16 | # Add the following to ~/.bash_profile or your desired shell
17 | # configuration file:
18 |
19 | export NVM_DIR=$HOME/.nvm
20 | source $(brew --prefix nvm)/nvm.sh
21 |
22 | # You can set $NVM_DIR to any location, but leaving it unchanged from
23 | # /usr/local/Cellar/nvm/0.30.1 will destroy any nvm-installed Node installations
24 | # upon upgrade/reinstall.
25 |
26 | nvm install stable
27 | nvm alias default stable
28 |
--------------------------------------------------------------------------------
/.nvm-install-official.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Don't touch if cached
4 | if test ! -e $HOME/.nvm; then
5 | wget -O - $NVM_INSTALLER | bash
6 | else
7 | echo Using cached nvm install
8 | fi
9 |
--------------------------------------------------------------------------------
/.omf-install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo "Downloading latest installer..."
4 | wget -O - $OMF_INSTALLER > /tmp/install.fish
5 | echo "Installing Oh My Fish..."
6 | fish /tmp/install.fish --channel=dev
7 | echo "Installing dependencies..."
8 | fish -c "omf install"
9 |
--------------------------------------------------------------------------------
/.plugin-install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | PACKAGE=$HOME/.local/share/omf/pkg/nvm
4 |
5 | if test -e $PACKAGE; then
6 | unlink $PACKAGE >/dev/null 2>&1 || rm -rf $PACKAGE
7 | fi
8 |
9 | ln -s $PWD $PACKAGE
10 | fish -c "omf install foreign-env"
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Derek Willian Stavis
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | #### plugin-nvm
4 | > A nvm wrapper for [Oh My Fish][omf-link].
5 |
6 | [](/LICENSE)
7 | [](http://fishshell.com)
8 | [](https://www.github.com/oh-my-fish/oh-my-fish)
9 | [](https://travis-ci.org/derekstavis/plugin-nvm)
10 |
11 |
12 |
13 | ## Install
14 |
15 | ```fish
16 | $ omf install nvm
17 | ```
18 | **NB** You have to install **nvm** itself separately (the [curl method](https://github.com/creationix/nvm/blob/master/README.md#install-script) works fine under Fish too).
19 |
20 |
21 | ## Usage
22 |
23 | ```fish
24 | $ nvm --help
25 | ```
26 |
27 | If you have a custom `$NVM_DIR`, please add the following line to your `~/.config/fish/config.fish`, replacing the path accordingly:
28 |
29 | ```fish
30 | set -gx NVM_DIR /path/to/nvm
31 | ```
32 |
33 | Refresh your shell and you are good to go!
34 |
35 | ```fish
36 | refresh
37 | ```
38 |
39 | # License
40 |
41 | [MIT][mit] © [Derek Willian Stavis][author] et [al][contributors]
42 |
43 |
44 | [mit]: http://opensource.org/licenses/MIT
45 | [author]: http://github.com/derekstavis
46 | [omf-link]: https://www.github.com/oh-my-fish/oh-my-fish
47 | [contributors]: https://github.com/derekstavis/pkg-nvm/graphs/contributors
48 |
--------------------------------------------------------------------------------
/bundle:
--------------------------------------------------------------------------------
1 | package foreign-env
2 |
--------------------------------------------------------------------------------
/completions/nvm.fish:
--------------------------------------------------------------------------------
1 | set commands help install uninstall use run current ls ls-remote version \
2 | version-remote deactivate alias unalias reinstall-packages which
3 |
4 | function __nvm_complete_ls_remote
5 | if not test "$__nvm_ls_remote"
6 | set -g __nvm_ls_remote (fenv source $nvm_prefix/nvm.sh\; nvm_ls_remote\; nvm_ls_remote_iojs)
7 | end
8 |
9 | printf "%s\n" $__nvm_ls_remote
10 | end
11 |
12 | function __nvm_complete_ls
13 | if not test "$__nvm_ls"
14 | set -g __nvm_ls (fenv source $nvm_prefix/nvm.sh\; nvm_ls)
15 | end
16 |
17 | printf "%s\n" $__nvm_ls
18 | end
19 |
20 | complete -c nvm -f -d "Node Version Manager"
21 |
22 | complete -c nvm -f -n "__fish_seen_subcommand_from install" -a "(__nvm_complete_ls_remote)"
23 | complete -c nvm -f -n "__fish_seen_subcommand_from uninstall" -a "(__nvm_complete_ls)"
24 | complete -c nvm -f -n "__fish_seen_subcommand_from use" -a "(__nvm_complete_ls)"
25 | complete -c nvm -f -n "__fish_seen_subcommand_from which" -a "(__nvm_complete_ls)"
26 | complete -c nvm -f -n "__fish_seen_subcommand_from reinstall-packages" -a "(__nvm_complete_ls)"
27 | complete -c nvm -f -n "__fish_seen_subcommand_from run" -a "(__nvm_complete_ls)"
28 |
29 | complete -c nvm -f -n "__fish_use_subcommand" -a help -d "Show help message"
30 | complete -c nvm -f -n "__fish_use_subcommand" -a install -s -s -d "Download and install a , [-s] from source. Uses .nvmrc if available"
31 | complete -c nvm -f -n "__fish_use_subcommand" -a uninstall -d "Uninstall a version"
32 | complete -c nvm -f -n "__fish_use_subcommand" -a use -o --silent -d "Modify PATH to use . Uses .nvmrc if available"
33 | complete -c nvm -f -n "__fish_use_subcommand" -a run -d "Run with as arguments. Uses .nvmrc if available for "
34 | complete -c nvm -f -n "__fish_use_subcommand" -a current -d "Display currently activated version"
35 | complete -c nvm -f -n "__fish_use_subcommand" -a ls -d "List installed versions"
36 | complete -c nvm -f -n "__fish_use_subcommand" -a ls -d "List versions matching a given description"
37 | complete -c nvm -f -n "__fish_use_subcommand" -a ls-remote -d "List remote versions available for install"
38 | complete -c nvm -f -n "__fish_use_subcommand" -a version -d "Resolve the given description to a single local version"
39 | complete -c nvm -f -n "__fish_use_subcommand" -a version-remote -d "Resolve the given description to a single remote version"
40 | complete -c nvm -f -n "__fish_use_subcommand" -a deactivate -d "Undo effects of nvm on current shell"
41 | complete -c nvm -f -n "__fish_use_subcommand" -a alias -d "Set an alias named pointing to "
42 | complete -c nvm -f -n "__fish_use_subcommand" -a unalias -d "Deletes the alias named "
43 | complete -c nvm -f -n "__fish_use_subcommand" -a reinstall-packages -d "Reinstall global npm packages contained in to current version"
44 | complete -c nvm -f -n "__fish_use_subcommand" -a which -d "Display path to installed node version. Uses .nvmrc if available"
45 |
--------------------------------------------------------------------------------
/functions/nvm.fish:
--------------------------------------------------------------------------------
1 | function nvm -d "Node version manager"
2 | if test -e $nvm_prefix/nvm.sh
3 | if not type -q fenv
4 | echo "You need to install foreign-env plugin"
5 | return 1
6 | end
7 |
8 | fenv source $nvm_prefix/nvm.sh --no-use ';' nvm $argv
9 | else
10 | echo "You need to install nvm itself (see https://github.com/creationix/nvm#installation)"
11 | return 1
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/init.fish:
--------------------------------------------------------------------------------
1 | function init -a path --on-event init_nvm
2 | if type -q fenv
3 | set -q NVM_DIR; or set -gx NVM_DIR ~/.nvm
4 | set -g nvm_prefix $NVM_DIR
5 |
6 | type -q brew;
7 | and test -e (brew --prefix)/Cellar/nvm;
8 | and set -g nvm_prefix (brew --prefix nvm)
9 |
10 | fenv source $nvm_prefix/nvm.sh >/dev/null 2>&1
11 | end
12 |
13 | end
14 |
--------------------------------------------------------------------------------
/test/bootstrap.fish:
--------------------------------------------------------------------------------
1 | function it_should
2 | switch "$argv[1]"
3 | case '-s' '--single'
4 | case '*'
5 | if not test (count $argv) -ge 2
6 | echo 'usage: it_should "do something" "commands"'
7 | echo ' it_should -s "commands"'
8 | return 1
9 | end
10 | set duty $argv[1]
11 | end
12 |
13 | set commands $argv[2..-1]
14 | set -l progress (set_color yellow)TEST(set_color normal)
15 |
16 | set -q duty;
17 | and printf -- '\n - It should %s: %s' $duty $progress
18 | or printf -- "$progress"
19 |
20 | if set output (eval "$commands" 2>&1)
21 | set_color green
22 | printf '\b\b\b\bPASS'
23 | set_color normal
24 | return 0
25 | else
26 | set_color red
27 | printf '\b\b\b\bFAIL'
28 | set_color -u
29 | printf '\n\nError description\n'
30 | set_color normal
31 | set_color yellow
32 | printf -- '%s\n' $output >&2
33 | echo
34 | set_color normal
35 | return 1
36 | end
37 | end
38 |
39 | printf 'Running test suite...\n'
40 |
41 | for test in test/cases/*
42 | printf -- '- It should %s: ' (basename $test | sed 's/^[0-9]*_//;s/_/ /g;s/\.fish//g')
43 | source $test;
44 | or exit 1
45 | echo
46 | end
47 |
--------------------------------------------------------------------------------
/test/cases/100_initialise_environment.fish:
--------------------------------------------------------------------------------
1 | it_should "have NVM_DIR defined in environment" "set -q NVM_DIR"
2 |
--------------------------------------------------------------------------------
/test/cases/101_display_nvm_help.fish:
--------------------------------------------------------------------------------
1 | it_should "display help using nvm --help" "test (nvm --help 2>&1 | wc -c) -gt 1"
2 | it_should "display help using nvm with no arguments" "test (nvm 2>&1 | wc -c) -gt 1"
3 |
--------------------------------------------------------------------------------
/test/cases/102_display_current_node_version.fish:
--------------------------------------------------------------------------------
1 | it_should -s "test (nvm current 2>/dev/null | wc -c) -gt 1"
2 |
--------------------------------------------------------------------------------
/test/cases/103_list_node_versions.fish:
--------------------------------------------------------------------------------
1 | it_should "list locally installed node versions" "test (nvm ls 2>/dev/null | wc -c) -gt 1"
2 | it_should "list remote node versions" "test (nvm ls-remote 2>/dev/null | wc -c) -gt 1"
3 |
--------------------------------------------------------------------------------
/test/cases/104_switch_node_versions.fish:
--------------------------------------------------------------------------------
1 | it_should "install node version" "nvm install v4; nvm install v5"
2 | it_should "set default version" "nvm alias default v4"
3 | it_should "switch node version" "nvm use v5; test (node --version | cut -c2) = 5"
4 | it_should "return the correct node version" "test (node --version = nvm version)"
5 |
--------------------------------------------------------------------------------