diff --git a/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptStore.java b/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptStore.java index feba8b1d2..da94a6aeb 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptStore.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptStore.java @@ -19,7 +19,7 @@ public enum PredefinedScriptStore { () -> SimpleScriptStore.builder() .group(PredefinedScriptGroup.CLINK.getEntry()) .minimumDialect(ShellDialects.CMD) - .commands(file("starship_cmd.bat")) + .commands(file("clink.bat")) .executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY) .build()), CLINK_INJECT( @@ -46,18 +46,7 @@ public enum PredefinedScriptStore { .group(PredefinedScriptGroup.STARSHIP.getEntry()) .minimumDialect(ShellDialects.CMD) .script(SETUP_CLINK.getEntry()) - .commands( - """ - WHERE starship >NUL 2>NUL - IF NOT %ERRORLEVEL%==0 ( - winget install starship - SET "PATH=%PATH%;C:\\Program Files\\starship\\bin" - ) - - MKDIR "%USERPROFILE%\\.xpipe\\scriptdata\\starship" >NUL 2>NUL - echo load(io.popen('starship init cmd'):read("*a"))() > "%USERPROFILE%\\.xpipe\\scriptdata\\starship\\starship.lua" - clink inject --quiet --profile "%USERPROFILE%\\.xpipe\\scriptdata\\starship" - """) + .commands(file("starship_cmd.bat")) .executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY) .build()), STARSHIP_POWERSHELL( @@ -65,17 +54,7 @@ public enum PredefinedScriptStore { () -> SimpleScriptStore.builder() .group(PredefinedScriptGroup.STARSHIP.getEntry()) .minimumDialect(ShellDialects.POWERSHELL) - .commands( - """ - if (-not $(Get-Command -ErrorAction SilentlyContinue starship)) { - winget install starship - - # Update current process PATH environment variable - $env:Path=([System.Environment]::GetEnvironmentVariable("Path", "Machine"), [System.Environment]::GetEnvironmentVariable("Path", "User")) -match '.' -join ';' - } - - Invoke-Expression (&starship init powershell) - """) + .commands(file("starship_powershell.ps1")) .executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY) .build()); diff --git a/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/clink.bat b/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/clink.bat new file mode 100644 index 000000000..41b1f824f --- /dev/null +++ b/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/clink.bat @@ -0,0 +1,19 @@ +WHERE clink >NUL 2>NUL +IF %ERRORLEVEL%==0 ( + exit /b 0 +) + +SET "PATH=%PATH%;%USERPROFILE%\.xpipe\scriptdata\clink" +WHERE clink >NUL 2>NUL +IF %ERRORLEVEL%==0 ( + exit /b 0 +) + +echo ^ +$downloader = New-Object System.Net.WebClient;^ +$defaultCreds = [System.Net.CredentialCache]::DefaultCredentials;^ +if ($defaultCreds) {^ + $downloader.Credentials = $defaultCreds^ +}^ +$downloader.DownloadFile("https://github.com/chrisant996/clink/releases/download/v1.5.7/clink.1.5.7.36d0c6.zip", "$env:TEMP\clink.zip");^ +Expand-Archive -Force -LiteralPath "$env:TEMP\clink.zip" -DestinationPath "$env:USERPROFILE\.xpipe\scriptdata\clink"; | powershell -NoLogo >NUL diff --git a/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/starship_cmd.bat b/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/starship_cmd.bat index 41b1f824f..3d7b60199 100644 --- a/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/starship_cmd.bat +++ b/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/starship_cmd.bat @@ -1,19 +1,9 @@ -WHERE clink >NUL 2>NUL -IF %ERRORLEVEL%==0 ( - exit /b 0 +WHERE starship >NUL 2>NUL +IF NOT %ERRORLEVEL%==0 ( + winget install starship + SET "PATH=%PATH%;C:\\Program Files\\starship\\bin" ) -SET "PATH=%PATH%;%USERPROFILE%\.xpipe\scriptdata\clink" -WHERE clink >NUL 2>NUL -IF %ERRORLEVEL%==0 ( - exit /b 0 -) - -echo ^ -$downloader = New-Object System.Net.WebClient;^ -$defaultCreds = [System.Net.CredentialCache]::DefaultCredentials;^ -if ($defaultCreds) {^ - $downloader.Credentials = $defaultCreds^ -}^ -$downloader.DownloadFile("https://github.com/chrisant996/clink/releases/download/v1.5.7/clink.1.5.7.36d0c6.zip", "$env:TEMP\clink.zip");^ -Expand-Archive -Force -LiteralPath "$env:TEMP\clink.zip" -DestinationPath "$env:USERPROFILE\.xpipe\scriptdata\clink"; | powershell -NoLogo >NUL +MKDIR "%USERPROFILE%\\.xpipe\\scriptdata\\starship" >NUL 2>NUL +echo load(io.popen('starship init cmd'):read("*a"))() > "%USERPROFILE%\\.xpipe\\scriptdata\\starship\\starship.lua" +clink inject --quiet --profile "%USERPROFILE%\\.xpipe\\scriptdata\\starship" \ No newline at end of file diff --git a/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/starship_powershell.ps1 b/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/starship_powershell.ps1 new file mode 100644 index 000000000..571f12f52 --- /dev/null +++ b/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/starship_powershell.ps1 @@ -0,0 +1,8 @@ +if (-not $(Get-Command -ErrorAction SilentlyContinue starship)) { + winget install starship + + # Update current process PATH environment variable + $env:Path=([System.Environment]::GetEnvironmentVariable("Path", "Machine"), [System.Environment]::GetEnvironmentVariable("Path", "User")) -match '.' -join ';' +} + +Invoke-Expression (&starship init powershell) \ No newline at end of file