diff --git a/README.md b/README.md index 879e5a2..f52be6d 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,14 @@ Make sure to source `jabba.sh` in your environment if you skip it: ```sh [ -s "$JABBA_HOME/jabba.sh" ] && source "$JABBA_HOME/jabba.sh" ``` +> (in powershell) + +```powershell +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +Invoke-Expression ( + Invoke-WebRequest https://github.com/shyiko/jabba/raw/master/install.ps1 -UseBasicParsing +).Content +``` > In [fish](https://fishshell.com/) command looks a little bit different - `curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash; and . ~/.jabba/jabba.fish` diff --git a/install.ps1 b/install.ps1 index 1bf0980..4912d4b 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,7 +1,25 @@ $ErrorActionPreference = "Stop" -$jabbaHome = if ($env:JABBA_HOME) { $env:JABBA_HOME } else { if ($env:JABBA_DIR) { $env:JABBA_DIR } else { "$env:USERPROFILE\.jabba" } } +$sep = [IO.Path]::DirectorySeparatorChar +$jabbaHome = if ($env:JABBA_HOME) { + $env:JABBA_HOME +} else { + if ($env:JABBA_DIR) { + $env:JABBA_DIR + } else { + if($env:USERPROFILE){ + "$env:USERPROFILE" + $sep + ".jabba" + }else{ + "$env:HOME" + $sep + ".jabba" + } + } +} $jabbaVersion = if ($env:JABBA_VERSION) { $env:JABBA_VERSION } else { "latest" } +# The Windows values of the Platform enum are: +# 0 (Win32NT), 1 (Win32S), 2 (Win32Windows) and 3 (WinCE). +# Other values are larger and indicate non Windows operating systems +$isOnWindows = [System.Environment]::OSVersion.Platform.value__ > 3 +$jabbaExecutableName = $isOnWindows ? "jabba.exe" : "jabba" if ($jabbaVersion -eq "latest") { @@ -25,17 +43,35 @@ if ($env:JABBA_MAKE_INSTALL -eq "true") } else { - Invoke-WebRequest https://github.com/shyiko/jabba/releases/download/$jabbaVersion/jabba-$jabbaVersion-windows-amd64.exe -UseBasicParsing -OutFile $jabbaHome/bin/jabba.exe + # $isOnWindows, see top of the file + # macOS enum value: 6 + # Unix enum value: 4 + if($isOnWindows){ + Invoke-WebRequest https://github.com/shyiko/jabba/releases/download/$jabbaVersion/jabba-$jabbaVersion-windows-amd64.exe -UseBasicParsing -OutFile $jabbaHome/bin/$jabbaExecutableName + } + elseif([System.Environment]::OSVersion.Platform.value__ -eq 4 || [System.Environment]::OSVersion.Platform.value__ -eq 6){ + Invoke-WebRequest https://github.com/shyiko/jabba/releases/download/$jabbaVersion/jabba-$jabbaVersion-darwin-amd64 -UseBasicParsing -OutFile $jabbaHome/bin/$jabbaExecutableName + }else{ + $osArch = [System.Environment]::Is64BitOperatingSystem ? "amd64" : "386" + Invoke-WebRequest https://github.com/shyiko/jabba/releases/download/$jabbaVersion/jabba-$jabbaVersion-linux-${OSARCH} -UseBasicParsing -OutFile $jabbaHome/bin/$jabbaExecutableName + } } $ErrorActionPreference="SilentlyContinue" -& $jabbaHome\bin\jabba.exe --version | Out-Null + +if($isOnWindows){ + & "$jabbaHome\bin\$jabbaExecutableName" --version | Out-Null +}else{ + chmod a+x "$jabbaHome/bin/$jabbaExecutableName" + & "$jabbaHome/bin/$jabbaExecutableName" --version | Out-Null +} + $binaryValid = $? $ErrorActionPreference="Continue" if (-not $binaryValid) { - Write-Host @" -$jabbaHome\bin\jabba does not appear to be a valid binary. + Write-Host -ForegroundColor Yellow @" +$jabbaHome\bin\$jabbaExecutableName does not appear to be a valid binary. Check your Internet connection / proxy settings and try again. if the problem persists - please create a ticket at https://github.com/shyiko/jabba/issues. @@ -49,7 +85,7 @@ if the problem persists - please create a ticket at https://github.com/shyiko/ja function jabba { `$fd3=`$([System.IO.Path]::GetTempFileName()) - `$command="& '$jabbaHome\bin\jabba.exe' `$args --fd3 ```"`$fd3```"" + `$command="& '$jabbaHome\bin\$jabbaExecutableName' `$args --fd3 ```"`$fd3```"" & { `$env:JABBA_SHELL_INTEGRATION="ON"; Invoke-Expression `$command } `$fd3content=`$(Get-Content `$fd3) if (`$fd3content) { @@ -81,6 +117,6 @@ else Write-Host @" -Installation completed +Installation completed (you might need to restart your terminal for the jabba command to be available) (if you have any problems please report them at https://github.com/shyiko/jabba/issues) "@