Skip to content

Commit

Permalink
fix: Support for Windows with Git-Bash or MSYS Bash
Browse files Browse the repository at this point in the history
- .exe executables are shims to non-extensions path
- .bat files to reshim for cmd or Powershell
- .bat execute bash script with bash built Windows
  • Loading branch information
daramkun authored and 진재연 committed Jan 2, 2025
1 parent 31e8c93 commit 4504dfb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/commands/reshim.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 <<EOF >"$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"
Expand Down
3 changes: 3 additions & 0 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4504dfb

Please sign in to comment.