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

Modify path for the current session only #101

Closed
andreiborisov opened this issue Jan 27, 2020 · 11 comments
Closed

Modify path for the current session only #101

andreiborisov opened this issue Jan 27, 2020 · 11 comments
Labels
enhancement New feature or fix

Comments

@andreiborisov
Copy link

andreiborisov commented Jan 27, 2020

👋

What's the problem?

  • I have a bunch of fish scripts that run in the background and use system-wide installation of node. Global modification of PATH breaks them.
  • I have different projects I work in parallel that use different node versions. Modification of fish_user_paths affects all terminal sessions, therefore, all projects.
  • I want to write a wrapper around node that will automatically call the appropriate node version based on the context (without the need to call nvm explicitly, mainly for the scripts) and would love to use this package as a dependency.

Proposed solution

  • Make path modification behavior configurable through a variable. If the user chooses to, do not modify universal fish_user_paths, instead modify global PATH variable on the command usage that will affect only the current fish session.

Are you willing to review and accept a PR for this?

Related: #93

@andreiborisov andreiborisov changed the title Use global path variable instead of universal one Modify node only for the current session Jan 27, 2020
@andreiborisov andreiborisov changed the title Modify node only for the current session Modify node for the current session only Jan 27, 2020
@andreiborisov andreiborisov changed the title Modify node for the current session only Modify path for the current session only Jan 27, 2020
@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.

@jorgebucaran
Copy link
Owner

jorgebucaran commented Apr 14, 2020

@yegorius @schrodincat Maybe you folks can help me test @schrodincat's proposal by writing a list of pros and cons for that approach. 🙏

@jorgebucaran jorgebucaran added the enhancement New feature or fix label Apr 14, 2020
@yegorius
Copy link

In my case I am almost always satisfied with my distro's default package of node (Arch Linux is rolling release distro so I get the latest official version of node in a matter of days), except for the special cases when some project requires an older version. In this case I temporarily switch with nvm in particular fish session while working on this project and I don't need the switch to be global or persistent.

@ujwal-setlur
Copy link

I need to different node versions in different shells...have older projects that work on node 10 only :-(

@jorgebucaran
Copy link
Owner

We could check for an .nvmrc file whenever PWD changes, and switch versions for that specific session only. But how do we persist that version when your Node program spawns a child process?

@yegorius @andreiborisov @ujwal-setlur @jackwestmoretab @thernstig

@andreiborisov
Copy link
Author

But how do we persist that version when your Node program spawns a child process?

Modify the global PATH instead of universal fish_user_paths. PATH is exported and should be inherited by child node processes.

@jorgebucaran
Copy link
Owner

Of course! Thanks, @andreiborisov!

@jorgebucaran jorgebucaran mentioned this issue Nov 14, 2020
@thernstig
Copy link

@jorgebucaran I definitely agree to modifying PATH for the current session only. I think that still having a possibility to modify "the global node version" is a good idea. Using/finding an .nvmrc in the directory tree would take precedence over the global one. This means you can easily walk in/out of project dirs but when outside them you still have some globally configured node version one can use e.g. for one-off npx install.

Even with that solution (allowing both "local" and "global" versions), I still have a slight problem with fish_user_paths. Reason being the way it works via specifying the full path to a path. This is bad for everyone using dotfiles, syncing their config/dotfiles across machines. The solution to this might however lie upon fish itself, see fish-shell/fish-shell#6641. But if it can be solved in this project as well that would be great. One way to solve it even for this project is to alter PATH as already suggested here for the project-local logic. In other words PATH would contain the path to the global configured node version, but when entering a directory it prepends the local, project-specific node version looking at .nvmrc.

But is the idea of automatically doing this by default when finding .nvmrc when PWD changes great? Some of us use tools like https://direnv.net/ which takes care of this for us for much more than just Node, so for us it could be problematic if you auto-switch.

@jorgebucaran
Copy link
Owner

Yes, and that's why we should only touch $PATH. I fully agree about avoiding $fish_user_paths.

@jorgebucaran
Copy link
Owner

Automatically switching versions when changing PWD should be easy to implement in userland (or perhaps even configurable—let's see), but never a default.

@jorgebucaran
Copy link
Owner

Hey! I just released 2.0. Now we modify your PATH only for the current session, thus installing (or activating) a Node version only changes your local environment.

See the README for documentation. 👋

@yegorius @ujwal-setlur @andreiborisov @thernstig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or fix
Projects
None yet
Development

No branches or pull requests

5 participants