Created
April 9, 2026 06:37
-
-
Save msnoigrs/83ffca3d8dcfcc681387c758b243b188 to your computer and use it in GitHub Desktop.
activate mise under MSYS2 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
| # shellcheck shell=bash | |
| __MISE_EXE="$(cygpath -u "${USERPROFILE}")/AppData/Local/Microsoft/WinGet/Links/mise.exe" | |
| __MISE_FLAGS=() | |
| __MISE_HOOK_ENABLED=1 | |
| export MISE_SHELL=bash | |
| # On first activation, save the original PATH | |
| # On re-activation, we keep the saved original | |
| if [ -z "${__MISE_ORIG_PATH:-}" ]; then | |
| export __MISE_ORIG_PATH="$PATH" | |
| fi | |
| __MISE_BASH_CHPWD_RAN=0 | |
| mise() { | |
| local command | |
| command="${1:-}" | |
| if [ "$#" = 0 ]; then | |
| command "$__MISE_EXE" | |
| return | |
| fi | |
| shift | |
| case "$command" in | |
| deactivate | shell | sh) | |
| # if argv doesn't contains -h,--help | |
| if [[ ! " $* " =~ " --help " ]] && [[ ! " $* " =~ " -h " ]]; then | |
| eval "$(command "$__MISE_EXE" "$command" "$@")" | |
| return $? | |
| fi | |
| ;; | |
| esac | |
| command "$__MISE_EXE" "$command" "$@" | |
| } | |
| _mise_hook() { | |
| local previous_exit_status=$? | |
| eval "$(mise hook-env "${__MISE_FLAGS[@]}" -s bash|sed -e 's/^export PATH/__PATH/g')" | |
| export PATH=$(cygpath -u -p "${__PATH}") | |
| return $previous_exit_status | |
| } | |
| if [ "$__MISE_HOOK_ENABLED" = "1" ]; then | |
| _mise_hook_prompt_command() { | |
| local previous_exit_status=$? | |
| if [[ ${__MISE_BASH_CHPWD_RAN:-0} == "1" ]]; then | |
| __MISE_BASH_CHPWD_RAN=0 | |
| return $previous_exit_status | |
| fi | |
| eval "$(mise hook-env "${__MISE_FLAGS[@]}" -s bash --reason precmd|sed -e 's/^export PATH/__PATH/g')" | |
| export PATH=$(cygpath -u -p "${__PATH}") | |
| return $previous_exit_status | |
| } | |
| _mise_hook_chpwd() { | |
| local previous_exit_status=$? | |
| __MISE_BASH_CHPWD_RAN=1 | |
| eval "$(mise hook-env "${__MISE_FLAGS[@]}" -s bash --reason chpwd|sed -e 's/^export PATH/__PATH/g')" | |
| export PATH=$(cygpath -u -p "${__PATH}") | |
| return $previous_exit_status | |
| } | |
| _mise_add_prompt_command() { | |
| if [[ "$(declare -p PROMPT_COMMAND 2>/dev/null)" == "declare -a"* ]]; then | |
| if [[ " ${PROMPT_COMMAND[*]} " != *" _mise_hook_prompt_command "* ]]; then | |
| PROMPT_COMMAND=("_mise_hook_prompt_command" "${PROMPT_COMMAND[@]}") | |
| fi | |
| elif [[ ";${PROMPT_COMMAND:-};" != *";_mise_hook_prompt_command;"* ]]; then | |
| local _mise_prompt_command_value="${PROMPT_COMMAND-}" | |
| printf -v PROMPT_COMMAND '%s' "_mise_hook_prompt_command${_mise_prompt_command_value:+;$_mise_prompt_command_value}" | |
| fi | |
| } | |
| _mise_add_prompt_command | |
| # shellcheck shell=bash | |
| export -a chpwd_functions | |
| function __zsh_like_cd() | |
| { | |
| \typeset __zsh_like_cd_hook | |
| if | |
| builtin "$@" | |
| then | |
| for __zsh_like_cd_hook in chpwd "${chpwd_functions[@]}" | |
| do | |
| if \typeset -f "$__zsh_like_cd_hook" >/dev/null 2>&1 | |
| then "$__zsh_like_cd_hook" || break # finish on first failed hook | |
| fi | |
| done | |
| true | |
| else | |
| return $? | |
| fi | |
| } | |
| # shellcheck shell=bash | |
| [[ -n "${ZSH_VERSION:-}" ]] || | |
| { | |
| function cd() { __zsh_like_cd cd "$@" ; } | |
| function popd() { __zsh_like_cd popd "$@" ; } | |
| function pushd() { __zsh_like_cd pushd "$@" ; } | |
| } | |
| chpwd_functions+=(_mise_hook_chpwd) | |
| fi | |
| _mise_hook | |
| # shellcheck shell=bash | |
| if [ -z "${_mise_cmd_not_found:-}" ]; then | |
| _mise_cmd_not_found=1 | |
| if [ -n "$(declare -f command_not_found_handle)" ]; then | |
| _mise_cmd_not_found_handle=$(declare -f command_not_found_handle) | |
| eval "${_mise_cmd_not_found_handle/command_not_found_handle/_command_not_found_handle}" | |
| fi | |
| command_not_found_handle() { | |
| if [[ $1 != "mise" && $1 != "mise-"* ]] && ${__MISE_EXE} hook-not-found -s bash -- "$1"; then | |
| _mise_hook | |
| "$@" | |
| elif [ -n "$(declare -f _command_not_found_handle)" ]; then | |
| _command_not_found_handle "$@" | |
| else | |
| echo "bash: command not found: $1" >&2 | |
| return 127 | |
| fi | |
| } | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment