Skip to content

Commit

Permalink
Update switch environment file from env_hook
Browse files Browse the repository at this point in the history
If the environment file is missing, recomputing it can take a noticeable
amount of time which delays every single return of the prompt when the
env_hook is enabled.

The use of atomic write on the environment file instead of a lock means
that the environment hooks can store the generated environment file if
it's missing, or needs regenerating.
  • Loading branch information
dra27 committed Jun 2, 2024
1 parent 21305bb commit 6700177
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/state/shellscripts/env_hook.csh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
alias precmd 'eval `opam env --shell=csh --readonly`'
alias precmd 'eval `opam env --shell=csh`'
2 changes: 1 addition & 1 deletion src/state/shellscripts/env_hook.fish
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function __opam_env_export_eval --on-event fish_prompt
eval (opam env --shell=fish --readonly 2> /dev/null)
eval (opam env --shell=fish 2> /dev/null)
end
2 changes: 1 addition & 1 deletion src/state/shellscripts/env_hook.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_opam_env_hook() {
local previous_exit_status=$?;
eval $(opam env --shell=bash --readonly 2> /dev/null <&- );
eval $(opam env --shell=bash 2> /dev/null <&- );
return $previous_exit_status;
};
if ! [[ "$PROMPT_COMMAND" =~ _opam_env_hook ]]; then
Expand Down
2 changes: 1 addition & 1 deletion src/state/shellscripts/env_hook.zsh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_opam_env_hook() {
eval $(opam env --shell=zsh --readonly 2> /dev/null <&-);
eval $(opam env --shell=zsh 2> /dev/null <&-);
}
typeset -ag precmd_functions;
if [[ -z ${precmd_functions[(r)_opam_env_hook]} ]]; then
Expand Down

0 comments on commit 6700177

Please sign in to comment.