From a9ca75c0cda0ab9f2b683f972dc4a2c65d1b1cd0 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Tue, 11 Jun 2024 11:03:35 +0800 Subject: [PATCH] fix(core): Use correct path in 'bash' (#6006) --- CHANGELOG.md | 3 ++- lib/core.ps1 | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index add88204..d88bca27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ - **scoop-info:** Fix download size estimating ([#5958](https://github.com/ScoopInstaller/Scoop/issues/5958)) - **decompress:** Match `extract_dir`/`extract_to` and archives ([#5983](https://github.com/ScoopInstaller/Scoop/issues/5983)) - **checkver:** Correct variable 'regex' to 'regexp' ([#5993](https://github.com/ScoopInstaller/Scoop/issues/5993)) -- **core:** Search for Git executable instead of any cmdlet ([#5998](https://github.com/ScoopInstaller/Scoop/pull/5998)) +- **core:** Search for Git executable instead of any cmdlet ([#5998](https://github.com/ScoopInstaller/Scoop/issues/5998)) +- **core:** Use correct path in 'bash' ([#6006](https://github.com/ScoopInstaller/Scoop/issues/6006)) ### Code Refactoring diff --git a/lib/core.ps1 b/lib/core.ps1 index 4865cc8e..2983c62d 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -1041,11 +1041,11 @@ function shim($path, $global, $name, $arg) { @( "#!/bin/sh", "# $resolved_path", - "if [ `$(echo `$WSL_DISTRO_NAME) ]", + "if [ `$WSL_INTEROP ]", 'then', " cd `$(wslpath -u '$(Split-Path $resolved_path -Parent)')", 'else', - " cd `"$((Split-Path $resolved_path -Parent).Replace('\', '/'))`"", + " cd `$(cygpath -u '$(Split-Path $resolved_path -Parent)')", 'fi', "java.exe -jar `"$resolved_path`" $arg `"$@`"" ) -join "`n" | Out-UTF8File $shim -NoNewLine @@ -1058,7 +1058,7 @@ function shim($path, $global, $name, $arg) { warn_on_overwrite $shim $path @( - "#!/bin/sh", + '#!/bin/sh', "# $resolved_path", "python.exe `"$resolved_path`" $arg `"$@`"" ) -join "`n" | Out-UTF8File $shim -NoNewLine @@ -1066,14 +1066,22 @@ function shim($path, $global, $name, $arg) { warn_on_overwrite "$shim.cmd" $path @( "@rem $resolved_path", - "@bash `"$resolved_path`" $arg %*" + "@bash `"`$(wslpath -u '$resolved_path')`" $arg %* 2>nul", + '@if %errorlevel% neq 0 (', + " @bash `"`$(cygpath -u '$resolved_path')`" $arg %* 2>nul", + ')' ) -join "`r`n" | Out-UTF8File "$shim.cmd" warn_on_overwrite $shim $path @( - "#!/bin/sh", + '#!/bin/sh', "# $resolved_path", - "`"$resolved_path`" $arg `"$@`"" + "if [ `$WSL_INTEROP ]", + 'then', + " `"`$(wslpath -u '$resolved_path')`" $arg `"$@`"", + 'else', + " `"`$(cygpath -u '$resolved_path')`" $arg `"$@`"", + 'fi' ) -join "`n" | Out-UTF8File $shim -NoNewLine } }