From 430e9053bebaf3566498efabeff85943b65b3b1a Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 9 May 2024 21:16:47 +0100 Subject: [PATCH] feat(mise): add command wrapper function --- zsh/mise.zsh | 27 +++++++++++++++++++++++++++ zshrc | 1 + 2 files changed, 28 insertions(+) create mode 100644 zsh/mise.zsh diff --git a/zsh/mise.zsh b/zsh/mise.zsh new file mode 100644 index 0000000..211d1ee --- /dev/null +++ b/zsh/mise.zsh @@ -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=`, and + # have the relevant environment variables from the relevant + # `.mise..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 diff --git a/zshrc b/zshrc index dfb239b..6412138 100644 --- a/zshrc +++ b/zshrc @@ -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"