diff --git a/plugins/mise/README.md b/plugins/mise/README.md index 8ec05aab9..264a37282 100644 --- a/plugins/mise/README.md +++ b/plugins/mise/README.md @@ -30,3 +30,7 @@ mise use -g node@system Use system node as global default mise install node@20.0.0 Install a specific version number mise use -g node@20 Use node-20.x as global default ``` + +## Setting + +- `ZSH_MISE_AUTOEXPORT_VERSIONS`: if set to `true`, the plugin will register a `chpwd` hook to update environment variable to reflect the current configuration. The variables are constructed from the output of `mise -ls -c`, with the `MISE_TOOL_` prefix, and their value is set to the full version of the tool, e.g., `MĚ€ISE_TOOL_PYTHON=3.8.20``. This can be used when building prompts. diff --git a/plugins/mise/mise.plugin.zsh b/plugins/mise/mise.plugin.zsh index 96686f6aa..f61356a8e 100644 --- a/plugins/mise/mise.plugin.zsh +++ b/plugins/mise/mise.plugin.zsh @@ -22,6 +22,19 @@ if [[ ! -f "$ZSH_CACHE_DIR/completions/_$__mise" ]]; then _comps[$__mise]=_$__mise fi + +if [[ "$ZSH_MISE_AUTOEXPORT_VERSIONS" != true ]]; then + _updateMiseVersions() { + unset -m "MISE_TOOL_*" + eval $(mise ls -c --no-header \ + | sed 's/^\(\S\+\)\s\+\(\S\+\).*$/export MISE_TOOL_\U\1=\2/') + } + + autoload -U add-zsh-hook + add-zsh-hook chpwd _updateMiseVersions + _updateMiseVersions # Initial call to check the current directory at shell startup +fi + # Generate and load mise completion $__mise completion zsh >| "$ZSH_CACHE_DIR/completions/_$__mise" &| unset __mise