feat(mise): add command wrapper function

This commit is contained in:
Jim Myhrberg
2024-05-09 21:16:47 +01:00
parent ee559256c1
commit 430e9053be
2 changed files with 28 additions and 0 deletions

27
zsh/mise.zsh Normal file
View File

@@ -0,0 +1,27 @@
#
# mise extra setup
#
if command-exists mise; then
# Wrap a tool with "mise exec" if the tool is managed by mise. Primarily this
# ensures that the tool is run with correct environment variables set with
# mise.
#
# Specifically it allows calling a tool prefixed with `MISE_ENV=<name>`, and
# have the relevant environment variables from the relevant
# `.mise.<name>.toml` files loaded.
mise-wrap-tool() {
local executable="$1"
local tool="${2:-$executable}"
eval "${executable}() {
if mise current \"${tool}\" > /dev/null; then
mise exec \"${tool}\" -- \"${executable}\" \"\$@\"
else
command \"${executable}\" \"\$@\"
fi
}"
}
mise-wrap-tool terraform
fi

1
zshrc
View File

@@ -193,6 +193,7 @@ source "$DOTZSH/copilot.zsh"
source "$DOTZSH/emacs.zsh"
source "$DOTZSH/fzf.zsh"
source "$DOTZSH/less.zsh"
source "$DOTZSH/mise.zsh"
source "$DOTZSH/neovim.zsh"
source "$DOTZSH/nix.zsh"
source "$DOTZSH/tldr.zsh"