Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NVM.fish — 2.0 🎏 #123

Merged
merged 34 commits into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6cf2b9f
nvm.fish 2.0
jorgebucaran Nov 24, 2020
07e9510
Use actual list and list-remote output in README
jorgebucaran Nov 25, 2020
bef96c4
Use 2.0 in CI
jorgebucaran Nov 25, 2020
da2cf70
Create $nvm_data if it doesn't exist
jorgebucaran Nov 25, 2020
b93d84e
Improve docs
jorgebucaran Nov 26, 2020
b6f6c29
More consistency and discoverability
jorgebucaran Nov 26, 2020
24da6e0
Be verbose
jorgebucaran Nov 27, 2020
765f583
More strict version-ish matching
jorgebucaran Nov 27, 2020
06d2985
Uninstall help
jorgebucaran Nov 27, 2020
45e65ef
an
jorgebucaran Nov 27, 2020
7d080c0
Add uninstall completions
jorgebucaran Nov 27, 2020
bf30d42
Miscellaneous
jorgebucaran Nov 27, 2020
3105b62
Help info
jorgebucaran Nov 27, 2020
c1a209d
Update index on install; complete install iff index exists
jorgebucaran Nov 29, 2020
4517822
Don't exit 1 if version isn't currently active
jorgebucaran Nov 29, 2020
537abb6
Flip var declaration order
jorgebucaran Nov 29, 2020
c59712d
Move nvm_data creation to install event
jorgebucaran Dec 1, 2020
4c92375
Use ! instead of not
jorgebucaran Dec 2, 2020
328b1c3
Don't use --show-error; looks like I added it by mistake
jorgebucaran Dec 2, 2020
077e295
Use --fail to see if curl will shut up on `curl: (23)` error
jorgebucaran Dec 3, 2020
8dd1ad5
Use -o - to see if it changes anything
jorgebucaran Dec 3, 2020
c2a87ba
Use --no-buffer?
jorgebucaran Dec 3, 2020
c3defbb
Revert to no extra flags
jorgebucaran Dec 4, 2020
6eb6cc5
Issues was while updating index, don't use --show-error
jorgebucaran Dec 4, 2020
8745258
download index sounds more idiomatic
jorgebucaran Dec 4, 2020
1fd7354
Install as local plugin
jorgebucaran Dec 4, 2020
eb775a7
Send install event errors to null
jorgebucaran Dec 4, 2020
4379343
! instead of not
jorgebucaran Dec 4, 2020
cd6cf4e
Simplify nvm use
jorgebucaran Dec 4, 2020
77217e9
Refactor commands for better readability
jorgebucaran Dec 4, 2020
bd8ded3
Improve README a bit
jorgebucaran Dec 4, 2020
91f77ab
Words
jorgebucaran Dec 4, 2020
662c0e6
2.0.0
jorgebucaran Dec 4, 2020
664807d
Stop using nvm_version variable
jorgebucaran Dec 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ name: CI
on: push

jobs:
build:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- run: |
sudo add-apt-repository -y ppa:fish-shell/nightly-master
- name: Install Fish
run: |
sudo apt-add-repository -yn ppa:fish-shell/release-3
sudo apt-get update
sudo apt-get -y install fish
- run: |
curl git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish
fish -c "fisher add . && nvm use lts && node -v"


sudo apt-get install -y fish

- name: Install Fisher
run: curl -sL git.io/fisher | source && fisher install jorgebucaran/fisher
shell: fish {0}

- name: Install Nvm
run: |
fisher install jorgebucaran/nvm.fish@2.0
set -l v 14.0.0
nvm install $v
test (node --version) = v$v
shell: fish {0}
131 changes: 62 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,125 +1,118 @@
# nvm.fish
# NVM.fish

> 100% pure-<a href="https://fishshell.com" title="friendly interactive shell">fish</a> Node.js version manager.
> 100% pure-[Fish](https://fishshell.com) Node version management.

- `.nvmrc` support.
- Seamless shell integration. <kbd>Tab</kbd>-completions? You got them.
- No dependencies, no subshells, no configuration setup, no fluff—it's so easy it hurts.
- Because nvm.fish runs natively by fish, it's insanely fast ([see this discussion](https://github.com/jorgebucaran/fish-nvm/issues/82)).
Not [_that_](https://github.com/nvm-sh/nvm) POSIX-compatible script. Designed for [Fish](), this tool helps you manage different versions of Node on a single local environment. Quickly install and switch between runtimes without cluttering your home directory or breaking system-wide scripts. Here are some of the highlights:

![](https://gistcdn.githack.com/jorgebucaran/00f6d3f301483a01a00e836eb17a2b3e/raw/26625256b5e5ccb632f990727db70055ae24e584/nvm.fish.svg)
- No dependencies, no setup, no clutter—it just works.
- <kbd>Tab</kbd>-completable seamless shell integration.
- `.node-version` and `.nvmrc` support. ✅
- [XDG Base Directory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) friendly.
<!-- - Hot symlink switching—absolute speed unlocked. -->
<!-- - Automatic version switching on `$PWD` change. -->

## Installation

Install with [Fisher](https://github.com/jorgebucaran/fisher) (recommended):
Install with [Fisher](https://github.com/jorgebucaran/fisher):

```console
fisher install jorgebucaran/nvm.fish
```

<details>
<summary>Not using a package manager?</summary>
## Quickstart

###
Install the latest Node release and start using it.

Copy [`conf.d/nvm.fish`](conf.d/nvm.fish), [`functions/nvm.fish`](functions/nvm.fish), and [`completions/nvm.fish`](completions/nvm.fish) to your fish configuration directory preserving the directory structure.
```console
nvm install latest
```

```fish
set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
Install the latest [LTS](https://github.com/nodejs/Release) (long-term support) Node release.

for i in conf.d functions completions
curl https://git.io/$i.nvm.fish --create-dirs -sLo $XDG_CONFIG_HOME/fish/$i/nvm.fish
end
```console
nvm install lts
```

To uninstall nvm, just run:
Install an older LTS release by codename.

```
rm -f $XDG_CONFIG_HOME/fish/{conf.d,functions,completions}/nvm.fish && emit nvm_uninstall
```console
nvm install carbon
```

</details>
> Installs `8.16.2`, the latest release of the Carbon LTS line.

## Quickstart

Download and switch to the latest Node.js release.
Or install a specific version of Node.

```console
nvm use latest
nvm install v12.9.1
```

> **Note:** This downloads the latest Node.js release tarball from the [official mirror](https://nodejs.org/dist), extracts it to <code>[\$XDG_CONFIG_HOME](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables)/nvm</code> and modifies your `$PATH` so it can be used immediately. Learn more about the Node.js release schedule [here](https://github.com/nodejs/Release).
> Supports full or partial version numbers, starting with an optional "v".

Download and switch to the latest LTS (long-term support) Node.js release.
The `nvm install` command activates the specified Node version only in the current environment. If you want to set the default version for new shells use:

```console
nvm use lts
```fish
set -U nvm_default_version v12.9.1
jorgebucaran marked this conversation as resolved.
Show resolved Hide resolved
```

You can create a `.nvmrc` file in the root of your project (or any parent directory) and run `nvm` to use the version in it. `nvm` will try to find the nearest `.nvmrc` file, traversing the directory tree from the current working directory upwards.
Activate a version you've already installed.

```console
node -v > .nvmrc
nvm
nvm use lts
jorgebucaran marked this conversation as resolved.
Show resolved Hide resolved
```

Run `nvm` in any subdirectory of a directory with an `.nvmrc` file to switch to the version from that file. Similarly, running `nvm use <version>` updates that `.nvmrc` file with the specified version.
List which versions you have installed (includes your system Node if there is one).

```console
├── README.md
├── dist
├── node_modules
├── package.json
└── src
└── index.js
$ nvm list
system
v8.17.0 lts/carbon
v12.9.1
▶ v14.15.1 lts/fermium
v15.3.0 latest
```

Or list all the Node versions available to install.

```console
echo lts >.nvmrc
cd src
nvm
node -v
v10.15.1
$ nvm list-remote
...
v14.13.1
v14.14.0
v14.15.0 lts/fermium
▶ v14.15.1 lts/fermium ✓
v15.0.0
v15.0.1
v15.1.0
v15.2.0
v15.2.1
v15.3.0 latest ✓
```

### Listing versions

List all the supported Node.js versions you can download and switch to.
Want to remove a Node version? You can do that too.

```console
nvm ls
nvm remove v12.9.1
jorgebucaran marked this conversation as resolved.
Show resolved Hide resolved
```

```console
...
10.14.2 (lts/dubnium)
10.15.0 (lts/dubnium)
11.0.0
11.1.0
11.2.0
11.3.0
11.4.0
11.5.0
11.6.0
11.7.0 (latest/current)
If you would like to use a different mirror of the Node binaries, for example, if you're behind a firewall, use:

```fish
set -g nvm_mirror https://npm.taobao.org/mirrors/node
jorgebucaran marked this conversation as resolved.
Show resolved Hide resolved
```

You can use a regular expression to narrow down the output.
## `.nvmrc`
jorgebucaran marked this conversation as resolved.
Show resolved Hide resolved

```console
nvm ls '^8.[4-6]'
```
An `.nvmrc` file makes it easy to peg a specific version of Node for different projects. Just create an `.nvmrc` (or `.node-version`) file containing a version number or alias, e.g., `latest`, `lts`, `carbon`, in the root of your project.

```console
8.4.0 (lts/carbon)
8.5.0 (lts/carbon)
8.6.0 (lts/carbon)
node -v >.nvmrc
```

To customize the download mirror, e.g., if you are behind a firewall, you can set `$nvm_mirror`:
Then run `nvm install` to install and activate that version. Works from anywhere inside your project by traversing the directory hierarchy until a `.nvmrc` is found.

jorgebucaran marked this conversation as resolved.
Show resolved Hide resolved
```console
set -g nvm_mirror http://npm.taobao.org/mirrors/node
nvm install
```

## License
Expand Down
19 changes: 14 additions & 5 deletions completions/nvm.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
complete -xc nvm -n __fish_use_subcommand -a ls -d "List available versions matching <regex>"
complete -xc nvm -n __fish_use_subcommand -a use -d "Download <version> and modify PATH so it's available"
complete -xc nvm -n __fish_use_subcommand -a --help -d "Show usage help"
complete -xc nvm -n __fish_use_subcommand -a --version -d "Show the current version of nvm"
complete -c nvm --exclusive --long help -d ""
complete -c nvm --exclusive --long version -d ""

nvm complete
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a install -d ""
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a use -d ""
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a list -d ""
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a list-remote -d ""
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a remove -d ""
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a current -d ""
complete -c nvm --exclusive --condition "__fish_seen_subcommand_from install" -a "(string split ' ' <$nvm_data/.index)"
complete -c nvm --exclusive --condition "__fish_seen_subcommand_from remove" -a "(_nvm_list | string split ' ' | string replace system '')"
complete -c nvm --exclusive --condition "__fish_seen_subcommand_from use" -a "(_nvm_list | string split ' ')"

set -q nvm_default_version \
&& complete -c nvm --exclusive --condition "__fish_seen_subcommand_from use remove" -a default
29 changes: 18 additions & 11 deletions conf.d/nvm.fish
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
set -g nvm_version 1.1.0

set --query XDG_DATA_HOME \
&& set --global nvm_data $XDG_DATA_HOME/nvm \
|| set --global nvm_data ~/.local/share/nvm

if set --query nvm_default_version && not set --query nvm_current_version
nvm use $nvm_default_version >/dev/null
end

function _nvm_uninstall -e nvm_uninstall
if test -s "$nvm_config/version"
read -l ver <$nvm_config/version
if set -l i (contains -i -- "$nvm_config/$ver/bin" $fish_user_paths)
set -e fish_user_paths[$i]
end
command rm -f $nvm_config/version
end
# command rm -rf $nvm_data

set --query nvm_current_version && _nvm_version_deactivate $nvm_current_version

for name in (set -n | command awk '/^nvm_/')
set -e "$name"
for var in nvm_{version,current_version,default_node,data}
set --erase $var
end

functions -e (functions -a | command awk '/^_nvm_/')
end
complete --erase --command nvm
functions --erase (functions --all | string match --entire --regex "^_nvm_")
end
12 changes: 12 additions & 0 deletions functions/_nvm_list.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function _nvm_list
set --local nodes $nvm_data/*

if set --query nodes[1]
string match --entire --regex (
string match --regex "v\d.+" $nodes | string escape --style=regex | string join "|"
) <$nvm_data/.index
end

command --all node | string match --quiet --invert --regex "^$nvm_data" && echo system
end

5 changes: 5 additions & 0 deletions functions/_nvm_version_activate.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function _nvm_version_activate -a ver
_nvm_version_deactivate $nvm_current_version
set --global --export nvm_current_version $ver
set --prepend PATH $nvm_data/$ver/bin
end
4 changes: 4 additions & 0 deletions functions/_nvm_version_deactivate.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function _nvm_version_deactivate -a ver
test "$nvm_current_version" = "$ver" && set --erase nvm_current_version
set --local index (contains --index -- $nvm_data/$ver/bin $PATH) && set --erase PATH[$index]
end
Loading