Created
March 23, 2026 08:24
-
-
Save Konfekt/abf8da0980c418dce8cffaaee3675fb2 to your computer and use it in GitHub Desktop.
activate mise under MSYS2 bash/zsh, in particular Git Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # To make Mise work in MSYS2/Cygwin, see | |
| # https://github.com/jdx/mise/discussions/3961#discussioncomment-16024383 | |
| # -- 1. Locate the mise binary ------------------------------------------ | |
| local mise_bin="" | |
| if [[ -n "$MSYSTEM" ]]; then | |
| # MSYS2 / Cygwin: prefer the Windows-native exe resolved through cygpath | |
| local scoop_shim_dir="$(/usr/bin/cygpath -u "$USERPROFILE")/scoop/shims" | |
| local scoop_mise="${scoop_shim_dir}/mise" | |
| if command -v mise.exe >/dev/null 2>&1; then | |
| mise_bin="$(/usr/bin/cygpath -u "$(command -v mise.exe)")" | |
| elif [[ -x "$scoop_mise" ]]; then | |
| mise_bin="$scoop_mise" | |
| fi | |
| elif command -v mise >/dev/null 2>&1; then | |
| mise_bin="$(command -v mise)" | |
| fi | |
| [[ -n "$mise_bin" && -x "$mise_bin" ]] || return 0 | |
| # -- 2. Shell name ------------------------------------------------------ | |
| local shell_name="${SHELL:-bash}" | |
| # -- 3. MSYS2-specific path fixup & activation ------------------------- | |
| if [[ -n "$MSYSTEM" ]]; then | |
| # Guard: only run once per session | |
| [[ -z "${__MISE_ORIG_PATH+X}" ]] || return 0 | |
| # Expose a wrapper so bare `mise` invocations work in MSYS2 | |
| _MISE_EXE_UNIX="$mise_bin" | |
| mise() { command "$_MISE_EXE_UNIX" "$@"; } | |
| export MISE_EXE="$_MISE_EXE_UNIX" | |
| export MISE_SHELL=bash # mise itself always expects "bash" compat here | |
| # Generate the activation script | |
| local activate_script | |
| activate_script="$("$mise_bin" activate "$shell_name")" | |
| # Convert the first PATH= export from Windows-style to Unix-style | |
| local win_path_line | |
| win_path_line="$(printf '%s\n' "$activate_script" \ | |
| | sed -n 's/^export PATH="\([^"]*\)".*$/\1/p')" | |
| if [[ -n "$win_path_line" ]]; then | |
| local unix_path_line | |
| unix_path_line="$(/usr/bin/cygpath -u -p "$win_path_line")" | |
| activate_script="$(printf '%s\n' "$activate_script" \ | |
| | awk -v newpath="$unix_path_line" \ | |
| 'BEGIN{done=0} { | |
| if (!done && $0 ~ /^export PATH=/) { | |
| print "export PATH=\"" newpath "\""; done=1 | |
| } else { print $0 } | |
| }')" | |
| fi | |
| # Replace any remaining Windows-style mise.exe references | |
| activate_script="$(printf '%s\n' "$activate_script" \ | |
| | sed -E "s@[A-Za-z]:\\\\[^\"']*\\\\mise\.exe@$_MISE_EXE_UNIX@g")" | |
| eval "$activate_script" | |
| eval "$("$mise_bin" hook-env -s "$shell_name")" | |
| # Install a hook that converts PATH back to Unix form after mise touches it | |
| __mise_fix_path() { | |
| export PATH="$(/usr/bin/cygpath -u -p "$PATH")" | |
| } | |
| if [[ "$shell_name" == "zsh" ]]; then | |
| autoload -Uz add-zsh-hook | |
| add-zsh-hook precmd __mise_fix_path | |
| else | |
| PROMPT_COMMAND="__mise_fix_path${PROMPT_COMMAND:+;$PROMPT_COMMAND}" | |
| fi | |
| __mise_fix_path | |
| # -- 4. Native (Linux / macOS / plain WSL) activation ------------------- | |
| else | |
| eval "$("$mise_bin" activate "$shell_name")" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment