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

perf(shell/zsh.rs): avoid hook-env execution on Enter without command #2861

Merged
merged 10 commits into from
Nov 5, 2024
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
source: src/cli/deactivate.rs
expression: output
snapshot_kind: text
---
export PATH='$PATH'
precmd_functions=( ${precmd_functions:#_mise_hook} )
precmd_functions=( ${precmd_functions:#_mise_hook_cmd} )
chpwd_functions=( ${chpwd_functions:#_mise_hook} )
unset -f _mise_hook_cmd
unset -f _mise_hook
unset -f mise
unset MISE_SHELL
10 changes: 8 additions & 2 deletions src/shell/snapshots/mise__shell__zsh__tests__activate.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: src/shell/zsh.rs
expression: "zsh.activate(exe, \" --status\".into())"
snapshot_kind: text
---
export MISE_SHELL=zsh
export __MISE_ORIG_PATH="$PATH"
Expand Down Expand Up @@ -29,9 +30,14 @@ mise() {
_mise_hook() {
eval "$(/some/dir/mise hook-env --status -s zsh)";
}
_mise_hook_cmd() {
if [[ -n "$ZLAST_COMMANDS" ]]; then
_mise_hook;
fi
}
typeset -ag precmd_functions;
if [[ -z "${precmd_functions[(r)_mise_hook]+1}" ]]; then
precmd_functions=( _mise_hook ${precmd_functions[@]} )
if [[ -z "${precmd_functions[(r)_mise_hook_cmd]+1}" ]]; then
precmd_functions=( _mise_hook_cmd ${precmd_functions[@]} )
fi
typeset -ag chpwd_functions;
if [[ -z "${chpwd_functions[(r)_mise_hook]+1}" ]]; then
Expand Down
4 changes: 3 additions & 1 deletion src/shell/snapshots/mise__shell__zsh__tests__deactivate.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
source: src/shell/zsh.rs
expression: replace_path(&deactivate)
snapshot_kind: text
---
precmd_functions=( ${precmd_functions:#_mise_hook} )
precmd_functions=( ${precmd_functions:#_mise_hook_cmd} )
chpwd_functions=( ${chpwd_functions:#_mise_hook} )
unset -f _mise_hook_cmd
unset -f _mise_hook
unset -f mise
unset MISE_SHELL
12 changes: 9 additions & 3 deletions src/shell/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ impl Shell for Zsh {
_mise_hook() {{
eval "$({exe} hook-env{flags} -s zsh)";
}}
_mise_hook_cmd() {{
if [[ -n "$ZLAST_COMMANDS" ]]; then
_mise_hook;
fi
}}
typeset -ag precmd_functions;
if [[ -z "${{precmd_functions[(r)_mise_hook]+1}}" ]]; then
precmd_functions=( _mise_hook ${{precmd_functions[@]}} )
if [[ -z "${{precmd_functions[(r)_mise_hook_cmd]+1}}" ]]; then
precmd_functions=( _mise_hook_cmd ${{precmd_functions[@]}} )
fi
typeset -ag chpwd_functions;
if [[ -z "${{chpwd_functions[(r)_mise_hook]+1}}" ]]; then
Expand Down Expand Up @@ -80,8 +85,9 @@ impl Shell for Zsh {

fn deactivate(&self) -> String {
formatdoc! {r#"
precmd_functions=( ${{precmd_functions:#_mise_hook}} )
precmd_functions=( ${{precmd_functions:#_mise_hook_cmd}} )
chpwd_functions=( ${{chpwd_functions:#_mise_hook}} )
unset -f _mise_hook_cmd
unset -f _mise_hook
unset -f mise
unset MISE_SHELL
Expand Down
Loading