Skip to content

Commit 6872608

Browse files
committed
Update PATH in place in env hook
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 #6815 Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
1 parent 5888e21 commit 6872608

5 files changed

Lines changed: 5 additions & 4 deletions

File tree

master_changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ users)
118118
## Client
119119

120120
## Shell
121+
* Update PATH in place in env hook [#6859 @gridbugs fix #6815]
121122

122123
## Internal
123124
* Improve cache-loading performance when using OCaml >= 5.4 by using `Gc.ramp_up` [#6515 @dra27]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
alias precmd 'eval `opam env --shell=csh --readonly`'
1+
alias precmd 'eval `opam env --shell=csh --readonly --inplace-path`'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function __opam_env_export_eval --on-event fish_prompt
2-
eval (opam env --shell=fish --readonly 2> /dev/null)
2+
eval (opam env --shell=fish --readonly --inplace-path 2> /dev/null)
33
end

src/state/shellscripts/env_hook.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
_opam_env_hook() {
22
local previous_exit_status=$?;
3-
eval $(opam env --shell=bash --readonly 2> /dev/null <&- );
3+
eval $(opam env --shell=bash --readonly --inplace-path 2> /dev/null <&- );
44
return $previous_exit_status;
55
};
66
if ! [[ "$PROMPT_COMMAND" =~ _opam_env_hook ]]; then

src/state/shellscripts/env_hook.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
_opam_env_hook() {
2-
eval $(opam env --shell=zsh --readonly 2> /dev/null <&-);
2+
eval $(opam env --shell=zsh --readonly --inplace-path 2> /dev/null <&-);
33
}
44
typeset -ag precmd_functions;
55
if [[ -z ${precmd_functions[(r)_opam_env_hook]} ]]; then

0 commit comments

Comments
 (0)