Closed thernstig closed 3 years ago
type --query nvm
.nvm install
if nvm use
fails and neither do we. But it's up to you to suggest that feature to the direnv
developers.type --quiet nvm
, right? Should I check which version of nvm.fish is installed as well? I suppose I can skip that check and just mention that it is a pre-requisite to use version 2? Or maybe not mention it at all, since it might work with version 1 as well?.config/direnv/lib/*.sh
. This mean, we could potentially add that functionality to this repo to add a file to .config/direnv/lib/nvm.fish.sh
which means it "just works" for direnv users. However, that also opens the door for many other direnv-like tools to want to add their own code to this repo, which might not be ideal. It is up to you @jorgebucaran.Nope, I meant type --query nvm
. Like:
type --query nvm && nvm use $node_version
I'd say forget the version check. It's too much work.
It is up to you...
I'll pass on this as I may choose to add automatic, async version switching in the future here instead.
https://fishshell.com/docs/current/cmds/type.html does not have --query
(set
does though)?
I just realized I can only use bash functionality to check for the existence of nvm.fish. The best option I could think of is to check if $nvm_data
exists, but it is not exported so that is not possible.
Okay, turns out type --quiet
is now type --query
in Fish 3.2, the version I'm using, so it's probably better to use type -q
to keep backward compatibility, since --quiet
will be removed in the future.
I just realized I can only use bash functionality to check for the existence of nvm.fish
I don't understand that. How are you planning to run nvm use
then?
You do realize that nvm
is not a binary, but a shell function (so it works kind of like a builtin). Just checking.
I don't understand that. How are you planning to run
nvm use
then?
I also just realized this is not possible... I should have thought this through better. Let me contemplate.
edit: Yes of course I realize nvm is not a binary, I did review the 2.0 update. I just did not think this through entirely.
I cannot come up with a sound solution, since I cannot use nvm use
. As such, I believe the best approach is to create an issue to clean up the current recommendation at https://github.com/direnv/direnv/wiki/Node#using-nvm-with-automatic-discovery and then just wait on:
I may choose to add automatic, async version switching in the future here instead.
I tried to get recent versions of nvm.fish and direnv work together, but I eventually gave up to update to 2.0 or above and pin jorgebucaran/nvm.fish@1.1.0
.
I really hope that alternative auto switching of node versions come.
Discussion was started in https://github.com/jorgebucaran/nvm.fish/pull/123, more specifically check https://github.com/jorgebucaran/nvm.fish/pull/123#issuecomment-738731666. This is a continuation to finalize a PR for the direnv repo's wiki on how to best use direnv with nvm 2.0.
In short, direnv is an extension for your shell. It augments existing shells with a new feature that can load and unload environment variables depending on the current directory. In combination with nvm.fish, it could be used to automatically load the node version for a specific project when entering that directory, and unloading it when leaving that directory.
For reference, check https://github.com/direnv/direnv/wiki/Node. It currently has a version for nvm.fish and nvm.sh combined, but it is outdated and not great. I intend to update it and add a nvm.fish 2.0 only version of
nvm_use()
, but need some guidance. If you read that page, the recommendation is to create ause_nvm()
bash function in~/.config/direnv/direnvrc
. That function can then be used by nvm.fish 2.0 users.nvm use
ornvm use <version>
instead of altering the path.nvm.fish
2.0 is installed on the system? The current version in the wiki does:nvm use
fails, the function should issue annvm install <version>
.