Repository navigation
NVM in fish #303
Description
Activity
May I request that this issue be reformatted in the form of a bug?
- NVM does not install if you use the fish shell.
- NVM does not work in the fish shell shell shell if previously installed in the bash shell. In fact, nvm isn't even in the path.
Reacted by Jason, Subrat Meher, Alexandr, Diva Martínez, Filip Sauer, Darren, Edwin Shepherd, Bogdan Barna, Hector Durán, Charles and 11 moreI attempted to test this out -
. nvm.shdidn'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.fishto 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. Ifnvm.fishfits in the main nvm project, I'll be happy to contribute it.Reacted by Davide Savazzi, Ruth Earle, Paul (xobb) Chubatyy, Austin Jackson, Aaron Adams, Gent Aliti, faizal kamaruddin, Ángel Cervera Claudio, Jamie Popkin, Alexandr and 24 more@alex7kom does your port share the same env vars and directory of node versions and global modules that standard
nvmdoes?@ljharb I tried to make it as close to standard
nvmas 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.@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.
@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 installednodes in one tab with a bash shell and another with a fish shell; they read the same.nvmrcfiles; 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?
I tried it, works nice, thanks! 👍 Just a thought, python virtualenv provides
bin/activatefor bash-ish shells andbin/activate.fishfor fish. If nvm could do something similar that would be nice. Also note that a.fishscript could still useshto delegate some work (installing etc) to the nvm bash version.Reacted by Michael Glasshttps://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.
Reacted by swedneck, Kevin Sylvestre, Vladimir Costa, Justin Horn and Tálison CardosoSorry 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.
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.
- added a commit that references this issue
on Feb 7, 2015 I also wrote a general wrapper to bring almost any bash utility to fish shell: https://github.com/edc/bass. It works flawlessly with nvm using syntax like
bass source ~/.nvm/nvm.sh \; nvm --version. For convenience, one can create an alias Fish function:function nvm bass source ~/.nvm/nvm.sh ';' nvm $argv endand then just use
nvm --version,nvm ls, etc.Reacted by Boris Aranovič, Wassim Dhif, jechol, Rémi Becheras, Chriest Yu, Louis Ledey, Gio d'Amelio, Ganesh Hegde, Anthony Grove, Adam Lutz and 77 moreReacted by Rémi Becheras, Meredith Leu, Gio d'Amelio, Ganesh Hegde, Anthony Grove, Adam Lutz, outro56, Fabian Morón Zirfas, Rômulo Ruas, Mo Yajouri and 17 moreReacted by Rémi Becheras, Gio d'Amelio, Ganesh Hegde, Anthony Grove, Marlom Girardi, outro56, Fabian Morón Zirfas, Rômulo Ruas, Mo Yajouri , Jonathan Kosgei and 29 more24 remaining items
@shangsunset wrong derek referenced in your comment earlier, but he obviously saw it.
Reacted by Derek StavisI just use
#!/bin/bash export NVM_SYMLINK_CURRENT=true if [[ -s $HOME/.nvm/nvm.sh ]] ; then source $HOME/.nvm/nvm.sh; else echo "No nvm found in `$HOME/.nvm/nvm.sh`"; fi nvm $@
And then add
/usr/local/sbin $HOME/.nvm/current/binto my path. This is why I implemented theNVM_SYMLINK_CURRENTvariable for nvm in the first placeReacted by Jakob Bowyer, Aurelien, Larry Fox and James McKinneyNVM 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-fileReacted by Greg McGrath, Vitalii Meshchaninov, david dinh, simone, Job van der Zwan, Osh Slomczynski and David VelascoWith this package installed, nvm works fine:
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"@elovin that wouldn’t leave nvm available inside fish to change the node version, which is the primary use case of nvm.
@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.Thanks @Globegitter has worked me too :
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.Reacted by Pothi Kalimuthu and Kyle AltendorfAdd the following to the fish config and restart the terminal (or reload the config):
function nvm bash -c "source ~/.nvm/nvm.sh; nvm $argv" end
Reacted by chaosuperDK, Kristen McWilliam and r0073dReacted by Derek Petersen, Jan Visser, Alexander Petrosyan, Stef, Superskyyy, Savvy Raghuvanshi, fyuan1316, Niko Diamadis , Martin Zaťko, Son Tran and 12 moreAdd the following to the fish config and restart the terminal (or reload the config):
function nvm
bash -c "source ~/.nvm/nvm.sh; nvm $argv"
endthis does indeed work well enough to execute
nvm. however, be aware that it does not propagate out thePATHmutation ofnvm use, for example. with the nvm interface being shell functions, it can end up doing things you don't expect if you mostly deal with 'programs' instead.
How do I install NVM for the fish shell?