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

Do not change fish_user_paths #93

Closed
thernstig opened this issue Oct 25, 2019 · 14 comments
Closed

Do not change fish_user_paths #93

thernstig opened this issue Oct 25, 2019 · 14 comments

Comments

@thernstig
Copy link

thernstig commented Oct 25, 2019

Adding a path in the home directory to the universal var fish_user_paths is not ideal. For example, for my install of fish-nvm it becomes SETUVAR fish_user_paths:/home/myusername/\x2econfig/nvm/13\x2e0\x2e0/bin

This is problematic due to the reason that some of us version control our home directory and certain parts of it, such as ~/.config/fish/ in order to have a unified working experience over multiple hosts.

Unfortunately there is no way to alter fish_variables so that it contains e.g. ~ (so it becomes agnostic as to what ny username is). This is due to that fish expands the path before adding it to fish_variables to the full path.

There are other reasons why setting an explicit user name is not ideal, such as in the case if a user changes his username. This would also invalidated the universal var set by fish-nvm. In short, no paths should be added to universal vars if they are a path in the user directory.

As such, it would be better to add the path to conf.d/nvm.fish as in there one can do set -gx PATH ~/some/path and it will be agnostic to the user name. It would also let me use different nodejs versions in different shells opened in fish.

@thernstig
Copy link
Author

I can see the reason for wanting to use a universal var. One might want to change the node version across all shells at the same time. At the same time, sometimes you might want different versions in e.g. different tabs.

I have not tested this yet, but maybe a middle-ground could be that the conf.d files for fish-nvm checks the user name at shell startup and if it is different then what is found in the fish_user_paths it alters the nvm path at startup. At least, this way it is possible to share the config between different hosts easily.

@jorgebucaran
Copy link
Owner

@thernstig What problem are you having? What's broken? What didn't work?

@thernstig
Copy link
Author

thernstig commented Oct 26, 2019

@jorgebucaran I was hoping that was clear from my initial post, but obviously I failed to get the point across :) What specific parts did you not understand, as I made several points in there. Or do you want to try to re-phrase the entire question (which I would be happy to do if needed)?

@thernstig
Copy link
Author

Does this comment from me and faho's reply explain it better? fish-shell/fish-shell#527 (comment)

@jorgebucaran
Copy link
Owner

I think I get it now.

@thernstig As such, it would be better to add the path to conf.d/nvm.fish as in there one can do set -gx PATH ~/some/path and it will be agnostic to the user name.

Sure, if that works for you, send me a PR.

@thernstig
Copy link
Author

thernstig commented Oct 27, 2019

@jorgebucaran I see two solutions, but it depends on what you prefer.

  1. Do you want nvm use <version> to still change all current shells nvm version? Like it currenlty does when using fish_user_paths to point to the bin dir.
  2. Or do you want nvm use <version> to change current shell only (global exported var)?)

For 1) I see a solution of having conf.d/nvm.fish add ~/.config/nvm/bin/ to PATH and in that directory have a symlink to the used version. nvm use <version> would then just update the symlink instead.

Do you see drawbacks of such a change?

@jorgebucaran
Copy link
Owner

@thernstig Do you want nvm use to still change all current shells nvm version? Like it currently does when using fish_user_paths to point to the bin dir.

That's what I'd expect to happen, so (1) is best for me based on how I use fish-nvm.

@indeyets
Copy link

indeyets commented Jan 7, 2020

@thernstig Do you want nvm use to still change all current shells nvm version? Like it currently does when using fish_user_paths to point to the bin dir.

That's what I'd expect to happen, so (1) is best for me based on how I use fish-nvm.

would it be possible to make this configurable somehow?
I usually find myself in situations when I do work on different projects which have different version-requirements and the whole point of NVM for me is to have project-specific nodejs versions

@andreiborisov
Copy link

andreiborisov commented Jan 27, 2020

@thernstig are you going to be satisfied with my solution #101?

An option to use a global path variable instead of universal fish_user_paths. Do you want to affect all fish sessions while not using fish_user_paths? Is it important for you?

@thernstig
Copy link
Author

thernstig commented Jan 27, 2020

@schrodincat I think it sounds good to support that nvm use X does not modify all session if hidden behind config. I believe it is orthogonal to my suggestion here in a sense As you can see in the pull request I sent in for this #94 I changed it to not use fish_user_paths at all.

My problem is moreso that I believe fish_user_paths is bad. Reason is that it saves to fish_variables, and inside fish_variables a user might have a lot of setup they want to sync between hosts (like in my case). So I wanted to get rid of the dependency on that.

At the same time, I do think that nvm use X is nice to have to change the node version used for all open shells.

What you are trying to solve can already be solved by https://direnv.net/, which is what I do myself. It is also possibly a better solution as it solves many more things that just the node version. I do not even have to type any nvm use X when moving between projects, the correct version is autoloaded on entry in the directories. Would that not solve your problem?

@andreiborisov
Copy link

@thernstig thanks for the hint about direnv, it seems it will be quite easy to befriend it with this package🙌

@thernstig
Copy link
Author

thernstig commented Jan 28, 2020

Here is a quick guide how to get it going:

Install node version 12.13.0 with nvm.
Install direnv.

Put this somewhere in your config.fish file.

# Node specific (for direnv to load)
set -gx NODE_VERSIONS ~/.config/nvm
set -gx NODE_VERSION_PREFIX ''

# Always keep at the end of this file
direnv hook fish | source

Put a .nvmrc file in your project dir with this content (as an example):

12.13.0

Put a .envrc file in your project dir with this content:

use node
layout node
watch_file .nvmrc

Now if you have another project with node, just repeat the .nvmrc and .envrc steps for that project, if you use node there. With another version if you will. It will automatically load the node env when you move between the project directories.

@thernstig
Copy link
Author

I can add the same setup can be done for any language. I do it for e.g. Python, Go etc. etc. When I move between project directories I never have to think about loading the correct versions, it just happens.

@yegorius
Copy link

This has already been discussed in #39. Please see my last comment there. I hope @jorgebucaran will include proposed changes into official version, as this feature has been requested multiple times.

Repository owner locked and limited conversation to collaborators Jul 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants