Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mise does not operate well under Git Bash on Windows #4048

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

roele
Copy link
Contributor

@roele roele commented Jan 10, 2025

Fixes #4011

Gave this a try but detection of msys or cygwin does not work via $OSTYPE as this is not available via env so env::var() does not return anything. Not sure how reliable my approach via MSYSTEM and PWD is though.

Another unresolved issue seems to be related to line breaks on cygwin. The .bashrc file does not source successfully until its opened and saved (without changes). Probably would require a dos2unix on cygwin, not sure why that is not an issue on msys.

$ source .bashrc
': not a valid identifiernctions
-bash: .bashrc: line 35: syntax error near unexpected token `$'\r''
'bash: .bashrc: line 35: `function __zsh_like_cd() {

@@ -1,5 +1,5 @@
# shellcheck shell=bash
export -a chpwd_functions
declare -a chpwd_functions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no -a flag for export i assume this is supposed to be declare?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roele roele force-pushed the issues/4011 branch 2 times, most recently from f90a9ea to 2a08412 Compare January 11, 2025 00:36
@jdx
Copy link
Owner

jdx commented Jan 11, 2025

for what it's worth, I'm not sure git bash is a necessary use-case for us. There are many alternatives like shims, powershell, and wsl for windows users.

@roele
Copy link
Contributor Author

roele commented Jan 11, 2025

I'm generally not a Windows user but I agree that shims and powershell seem to work well enough. Windows is a PITA anyways, in my last project Git Bash was my only option (was not allowed to use WSL or install anything else). While probably rare there might be some users restrained to such a setup.

@jdx
Copy link
Owner

jdx commented Jan 11, 2025

right but even then shims will work. What won't work is you won't see env vars unless you wrap things in tasks but as I'm sure you've heard me explain, that's kind of how I think projects should be setup anyways since it doesn't rely on shell extensions.

mise en would be another alternative

@roele
Copy link
Contributor Author

roele commented Jan 11, 2025

I noticed that when using shims in context of cygwin/mysys a .cmd suffix has to be added though.

@jdx
Copy link
Owner

jdx commented Jan 11, 2025

isn't that already happening?

@roele
Copy link
Contributor Author

roele commented Jan 11, 2025

What i mean is that i would expect for example that i can use java -version in Git Bash but instead i have to use java.cmd -version.

@jdx
Copy link
Owner

jdx commented Jan 11, 2025

is this something that can be configured with PATHEXT? or is there a git bash equivalent for that?

@roele
Copy link
Contributor Author

roele commented Jan 13, 2025

PATHEXT is a Windows environment variable and i am not aware of an equivalent in Git Bash/Cygwin. Emulating PATHEXT in Bash does also not seem to work.

export PATHEXT=.com:.exe:.bat:.cmd

if declare -f command_not_found_handle >/dev/null; then 
    eval "original_command_not_found_handle() $(declare -f command_not_found_handle|tail -n +2)"
fi
command_not_found_handle(){
    local PATHEXT_EXPANDED i
    IFS=: read -a PATHEXT_EXPANDED<<<"$PATHEXT"
    for i in "${PATHEXT_EXPANDED[@]}"; do
        if type "$1$i" &>/dev/null; then
            "$1$i" "${@:2}"
            return $?
        fi
    done
    if declare -f original_command_not_found_handle >/dev/null; then
        original_command_not_found_handle "$@"
    else
        return 127
    fi
}

While this PR makes activate work for Git Bash and Cygwin detection seems a bit hacky. I wonder if we should drop this for now. Having at least the shims work would be great though.

@roele
Copy link
Contributor Author

roele commented Jan 13, 2025

The following hook might be a workaround for the shims .cmd ending issue. We might simply document this as possible workaround in the troubleshooting docs "Windows problems" section.

command_not_found_handle()
{
   cmd=$1
   shift
   args=( "$@" )

   IFS=:
   for dir in $PATH; do
      for executable in $dir/$cmd.bat $dir/$cmd.cmd $dir/$cmd.exe; do
         if [ -f "$executable" ]; then
            "$executable" "${args[@]}"
            return
         fi
      done
   done

   orig_command_not_found_handle "$cmd" "${args[@]}"
} 
if declare -f command_not_found_handle >/dev/null; then 
    eval "orig_command_not_found_handle() $(declare -f command_not_found_handle|tail -n +2)"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mise does not operate well under GitBash on Windows
2 participants