You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I attempted to test this out - . nvm.sh didn't work in the fish shell, even with the shebang for /bin/sh or /bin/bash.
I'm not sure if a script can be portable across bash/sh/dash/ksh and still work in fish. For example, $? to indicate success doesn't work in fish, it's $status, which none of the other shells have.
Most worrying, all the other shells' function syntax doesn't work in fish. I suspect we'd need a brand new nvm.fish to make this work properly.
Not a self-promotion, but I did port nvm to fish, please check https://github.com/Alex7Kom/nvm-fish
I rewrote it entirely since fish is very different. If nvm.fish fits in the main nvm project, I'll be happy to contribute it.
svzdvd, ruthearle, paulchubatyy, au5ton, aadamsx and 27 more
@ljharb I tried to make it as close to standard nvm as possible, so it uses the same naming everywhere, and it should use the same directory of node versions if put in the same directory as standard nvm. However, I didn't update it for 4 months, so I'll need some time to achieve parity with nvm.
I hope I understood you right.
@alex7kom This is great! I wanted to implement nvm for fish, but never found the time to learn fish well enough to do it. You are right that a complete rewrite was needed.
@alex7kom Honestly, if you can commit to keeping your fish port up to date such that it can be a seamless drop-in for standard nvm, and i could simultaneously use installed nodes in one tab with a bash shell and another with a fish shell; they read the same .nvmrc files; and if it could use git-tagged versions; etc - what I'd prefer is for the install script to be able to intelligently install your fork rather than incorporate it into this repo.
I tried it, works nice, thanks! 👍 Just a thought, python virtualenv provides bin/activate for bash-ish shells and bin/activate.fish for fish. If nvm could do something similar that would be nice. Also note that a .fish script could still use sh to delegate some work (installing etc) to the nvm bash version.
Sorry to dredge up an old issue, but with all the recent hype about io.js, and with the latest nvm now supporting installing io.js, this has become a bigger issue for fish users again. The latest version of the nvm-fish fork is woefully outdated compared to current nvm, and so therefore can't be used to install io.js. Has any more thought been put into this?
There's a PR open to get it to work, but fish being wildly different than most shells, some of the changes required concern me. I'm still open to the possibility.
It works by running nvm in bash within a fish function, and doing some magic to pass the (relevant parts of the) environment through and export it again once nvm returns. Doing so incurs a noticeable delay (about 1 second) before nvm is run, but I think that's acceptable. Because it's just a wrapper, it will always work (unlike the nvm-fish port), requiring no maintenance while nvm can be updated at will, unless nvm changes significantly. Additionally, it uses the same nvm as other shells, so nodes (and ios) are shared (again, unlike the nvm-fish port). And it's less than two pagefuls of code ;P
It is similar in thought to #579 but less intrusive and requires no changes in nvm.
I have written a fish function which basically executes nvm in a bash login shell and sets the path accordingly: https://gist.github.com/calle2010/b3f0054c1d4b72394d0fda7f22d47b38
Since it modifies the $fish_users_paths variable the node installation is also available in a new shell without executing anything. So far this works for me.
Activity
djensen47 commentedon Oct 14, 2013
May I request that this issue be reformatted in the form of a bug?
ljharb commentedon Apr 20, 2014
I attempted to test this out -
. nvm.sh
didn't work in the fish shell, even with the shebang for /bin/sh or /bin/bash.I'm not sure if a script can be portable across bash/sh/dash/ksh and still work in fish. For example,
$?
to indicate success doesn't work in fish, it's$status
, which none of the other shells have.Most worrying, all the other shells' function syntax doesn't work in fish. I suspect we'd need a brand new
nvm.fish
to make this work properly.alex7kom commentedon Apr 20, 2014
Not a self-promotion, but I did port nvm to fish, please check https://github.com/Alex7Kom/nvm-fish
I rewrote it entirely since fish is very different. If
nvm.fish
fits in the main nvm project, I'll be happy to contribute it.ljharb commentedon Apr 20, 2014
@alex7kom does your port share the same env vars and directory of node versions and global modules that standard
nvm
does?alex7kom commentedon Apr 20, 2014
@ljharb I tried to make it as close to standard
nvm
as possible, so it uses the same naming everywhere, and it should use the same directory of node versions if put in the same directory as standardnvm
. However, I didn't update it for 4 months, so I'll need some time to achieve parity withnvm
.I hope I understood you right.
creationix commentedon Apr 21, 2014
@alex7kom This is great! I wanted to implement nvm for fish, but never found the time to learn fish well enough to do it. You are right that a complete rewrite was needed.
/me goes off to install fish and test it.
ljharb commentedon Apr 22, 2014
@alex7kom Honestly, if you can commit to keeping your fish port up to date such that it can be a seamless drop-in for standard
nvm
, and i could simultaneously use installednode
s in one tab with a bash shell and another with a fish shell; they read the same.nvmrc
files; and if it could use git-tagged versions; etc - what I'd prefer is for the install script to be able to intelligently install your fork rather than incorporate it into this repo.Thoughts?
wires commentedon May 28, 2014
I tried it, works nice, thanks! 👍 Just a thought, python virtualenv provides
bin/activate
for bash-ish shells andbin/activate.fish
for fish. If nvm could do something similar that would be nice. Also note that a.fish
script could still usesh
to delegate some work (installing etc) to the nvm bash version.Globegitter commentedon Aug 25, 2014
https://github.com/Alex7Kom/nvm-fish has worked great for me. Would love to see the main project support fish out of the box at some point.
doughsay commentedon Jan 29, 2015
Sorry to dredge up an old issue, but with all the recent hype about io.js, and with the latest nvm now supporting installing io.js, this has become a bigger issue for fish users again. The latest version of the nvm-fish fork is woefully outdated compared to current nvm, and so therefore can't be used to install io.js. Has any more thought been put into this?
ljharb commentedon Jan 29, 2015
There's a PR open to get it to work, but fish being wildly different than most shells, some of the changes required concern me. I'm still open to the possibility.
passcod commentedon Feb 7, 2015
I've written a wrapper that lets fish people use nvm seamlessly: https://github.com/passcod/nvm-fish-wrapper 🐟
It works by running nvm in bash within a fish function, and doing some magic to pass the (relevant parts of the) environment through and export it again once nvm returns. Doing so incurs a noticeable delay (about 1 second) before nvm is run, but I think that's acceptable. Because it's just a wrapper, it will always work (unlike the nvm-fish port), requiring no maintenance while nvm can be updated at will, unless nvm changes significantly. Additionally, it uses the same nvm as other shells, so nodes (and ios) are shared (again, unlike the nvm-fish port). And it's less than two pagefuls of code ;P
It is similar in thought to #579 but less intrusive and requires no changes in nvm.
35 remaining items
eugenet8k commentedon Aug 25, 2017
NVM has an example of a change directory hook to automatically call
nvm use
: https://github.com/creationix/nvm#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-fileIf you want the same in Fish, use this adopted function:
https://gist.github.com/eugenet8k/535bf3c51d1fc7c31cb8784e55d4dae4#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file
osbre commentedon Feb 11, 2020
With this package installed, nvm works fine:
https://github.com/FabioAntunes/fish-nvm
elovin commentedon Nov 18, 2021
An alternative is to setup nvm in zsh/bash and then switch to fish (e.g. on mac):/bin/zsh -c "source ~/.zshrc && /usr/local/bin/fish -i"
ljharb commentedon Nov 18, 2021
@elovin that wouldn’t leave nvm available inside fish to change the node version, which is the primary use case of nvm.
elovin commentedon Dec 1, 2021
@ljharb hm I'm not sure if I do something different in the setup then because I can switch between node versions just fine
Update:
You are right, I also use the workaround with bass, for some reason I still have to call zsh first though.
Toesandfeet commentedon Mar 17, 2023
alaslyalasel commentedon Mar 17, 2023
vladimiremi commentedon Jul 8, 2024
Thanks @Globegitter has worked me too :
https://github.com/Alex7Kom/nvm-fish
calle2010 commentedon Sep 19, 2024
I have written a fish function which basically executes nvm in a bash login shell and sets the path accordingly:
https://gist.github.com/calle2010/b3f0054c1d4b72394d0fda7f22d47b38
Since it modifies the $fish_users_paths variable the node installation is also available in a new shell without executing anything. So far this works for me.
kevinisaac commentedon Sep 20, 2024
Add the following to the fish config and restart the terminal (or reload the config):
meotimdihia commentedon Sep 21, 2024