Update PATH in place in env hook#6859
Conversation
98024e0 to
6872608
Compare
Prior to this change, the default behaviour of `opam init` was to register a shell hook which ran before each command, and added/moved the bin dir from the current opam switch to the beginning of the PATH variable. If a user has a custom bin directory at the beginning of their PATH containing an executable with the same name as an executable in their current opam switch, the executable in the opam switch will take precedence. This commit changes the behaviour of the shell hook to update the existing opam switch in PATH in place rather than prepending it, so the precedence of the opam switch relative to other dirs in PATH is preserved. This change doesn't affect the behaviour of running `eval $(opam env)`. Fixes ocaml#6815 Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
6872608 to
b896271
Compare
|
Thanks for the PR! We'll discuss it in the next opam dev meeting. |
kit-ty-kate
left a comment
There was a problem hiding this comment.
I like that idea, thanks for bringing options that i didn't know about.
After testing it live, i think the documentation of the option is somewhat misleading as to its behaviour when adding another switch directory to the PATH manually. The documentation says that it "replaces any pre-existing opam path" but it rather "replaces any previously-modified PATH component by opam".
As noted by @rjbou during our meeting, our testsuite is missing test for this option and it would be nice to have some before the full release (this can be done separately from this PR at a later date).
Once merged, we should remember to display a prominent note so that people know about this change. In particular, if their .bashrc/.zshrc file contain further additions to PATH after the source opam-init.sh line, they will now be place before opam in the PATH. This can be a breaking change for some people but this is also a "bug fix" in some regard given that it normalises the shape of the PATH in interactive shell mode vs. not interactive mode if someone adds things to their PATH after sourcing opam.
Prior to this change, the default behaviour of
opam initwas to register a shell hook which ran before each command, and added/moved the bin dir from the current opam switch to the beginning of the PATH variable. If a user has a custom bin directory at the beginning of their PATH containing an executable with the same name as an executable in their current opam switch, the executable in the opam switch will take precedence.This commit changes the behaviour of the shell hook to update the existing opam switch in PATH in place rather than prepending it, so the precedence of the opam switch relative to other dirs in PATH is preserved.
This change doesn't affect the behaviour of running
eval $(opam env).Fixes #6815