From 40ea0e1ce6ea3a093c36ca828ed471de74202105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=9E=AC=EC=97=B0=20=28Jin=20Jae-yeon=29?= Date: Thu, 24 Oct 2024 00:29:15 +0900 Subject: [PATCH] fix: Support for Windows with Git-Bash or MSYS Bash - .exe executables are shims to non-extensions path - .bat files to reshim for cmd or Powershell - .bat execute bash script with bash built Windows --- lib/commands/reshim.bash | 28 +++++++++++++++++++++++++++- lib/utils.bash | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/commands/reshim.bash b/lib/commands/reshim.bash index 2317973a..c5f116ad 100644 --- a/lib/commands/reshim.bash +++ b/lib/commands/reshim.bash @@ -78,7 +78,7 @@ write_shim_script() { local version=$2 local executable_path=$3 - if ! is_executable "$executable_path"; then + if ! is_executable "$executable_path" && ! is_executable "$executable_path.exe"; then return 0 fi @@ -107,6 +107,32 @@ $(sort -u <"$temp_versions_path") exec $(asdf_dir)/bin/asdf exec "${executable_name}" "\$@" # asdf_allow: ' asdf ' EOF + if [ "$OSTYPE" == "msys" ] || [ "$OSTYPE" == "win32" ]; then + cat <"$shim_path.bat" +@ECHO OFF +$(sort -u <"$temp_versions_path" | sed -En "s/# /REM /p") + +IF "%1"=="" ( + GOTO NO_ARGS +) ELSE ( + GOTO ARGS_EXIST +) + +:NO_ARGS +bash "$HOME/.asdf/shims/${executable_name}" +GOTO EXIT + +:ARGS_EXIST +SET ARGUMENTS=%* +SET ARGUMENTS=%ARGUMENTS:\\=\\\\% +bash "$HOME/.asdf/shims/${executable_name}" %ARGUMENTS% +GOTO EXIT + +:EXIT + +EOF + fi + rm "$temp_versions_path" chmod +x "$shim_path" diff --git a/lib/utils.bash b/lib/utils.bash index 21978a92..a36ed1e8 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -618,6 +618,9 @@ plugin_executables() { for bin_path in "${all_bin_paths[@]}"; do for executable_file in "$bin_path"/*; do if is_executable "$executable_file"; then + if [[ "$executable_file" == *".exe" ]]; then + executable_file=${executable_file::-4} + fi printf "%s\n" "$executable_file" fi done