-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Preserve the order of PATH locations when changing node versions #1316
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't necessarily agree with the claim that the user should be solely managing their PATH - by using nvm
, the user is explicitly ceding control of their PATH to it.
nvm.sh
Outdated
nvm_echo "${3-}${2-}" | ||
# if the initial path doesn’t contain an nvm path, prepend the supplementary | ||
# path | ||
elif [ "$(expr "${1-}" : ".*${NVM_DIR}/[^:]*${2-}.*")" = 0 ] || \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to avoid using expr
in nvm
because of https://github.com/koalaman/shellcheck/wiki/SC2003. Can this be written differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From that link:
sh doesn't have a great replacement for the : operator (regex match). ShellCheck tries not to warn when using expr with :
I'm not aware of another way to do this and still keep POSIX compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it use awk
or sed
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using grep
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, any posix tool is great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 😁
I'm not saying that the user is solely managing their path. Simply that it's up to the user to load their PATH-adapting utilities in an order that makes sense for them. In the current scenario,
Whilst I accept, as a user of In the current scenario:
In my fix:
In short, my argument is that the PATH doesn't serve only NVM. It serves other needs, too. Always has, always will. For NVM to assume that its needs and demands on the PATH trump the rest of the system's needs, always, no-questions-asked, no-prisoners-taken, is hostile to other tools. Tools that the user has chosen to run. I.e. that assumption is ultimately hostile to the user. Unix has always been about giving people the freedom to do stupid things. Because without it you don't have the freedom to do clever things. |
@zeorin let's give this one another shot - can you rebase it on latest master, and/or check the "allow edits" checkbox on the right hand column? |
@ljharb I rebased the pull request branch on master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more I try this out locally the more I'm convinced this is an excellent change.
Thanks for bearing with me!
nvm
may not be the only utility managing the PATH. The order of locations in the PATH matters, as executables in locations in the beginning of PATH will be shadowing executables that are in later locations.An example of this is when the output of
$(npm bin)
is prepended to the PATH. If nvm is used to change the node version after that, it should not change the order of path locations.It's up to the user to change the PATH in a way that they prefer, by loading utilities in the correct order.