|
3 | 3 |
|
4 | 4 | $ErrorActionPreference = "Stop" |
5 | 5 |
|
| 6 | +# Ensure TLS 1.2 for GitHub API/downloads (older Windows defaults to TLS 1.0) |
| 7 | +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 |
| 8 | + |
6 | 9 | # Configuration |
7 | | -$GOENV_ROOT = if ($env:GOENV_ROOT) { $env:GOENV_ROOT } else { "$HOME\.goenv" } |
| 10 | +$GOENV_ROOT = if ($env:GOENV_ROOT) { $env:GOENV_ROOT } else { Join-Path (if ($env:USERPROFILE) { $env:USERPROFILE } else { $HOME }) ".goenv" } |
8 | 11 | $GITHUB_REPO = "go-nv/goenv" |
9 | | -$INSTALL_DIR = "$GOENV_ROOT\bin" |
| 12 | +$INSTALL_DIR = Join-Path $GOENV_ROOT "bin" |
10 | 13 |
|
11 | | -# Colors |
12 | | -function Write-ColorOutput($ForegroundColor) { |
13 | | - $fc = $host.UI.RawUI.ForegroundColor |
14 | | - $host.UI.RawUI.ForegroundColor = $ForegroundColor |
15 | | - if ($args) { |
16 | | - Write-Output $args |
17 | | - } |
18 | | - $host.UI.RawUI.ForegroundColor = $fc |
| 14 | +# Colors — use Write-Host which works in non-interactive/piped contexts |
| 15 | +function Write-ColorOutput { |
| 16 | + param( |
| 17 | + [Parameter(Position=0)] |
| 18 | + [System.ConsoleColor]$ForegroundColor, |
| 19 | + [Parameter(Position=1, ValueFromRemainingArguments)] |
| 20 | + [string[]]$Message |
| 21 | + ) |
| 22 | + Write-Host ($Message -join ' ') -ForegroundColor $ForegroundColor |
19 | 23 | } |
20 | 24 |
|
21 | 25 | # Detect architecture |
@@ -85,35 +89,48 @@ function Install-Binary { |
85 | 89 | # Copy binary |
86 | 90 | $binaryPath = Join-Path $tmpDir "goenv.exe" |
87 | 91 | if (Test-Path $binaryPath) { |
88 | | - Copy-Item -Path $binaryPath -Destination "$INSTALL_DIR\goenv.exe" -Force |
| 92 | + Copy-Item -Path $binaryPath -Destination (Join-Path $INSTALL_DIR "goenv.exe") -Force |
89 | 93 | } else { |
90 | 94 | throw "Binary not found in archive" |
91 | 95 | } |
92 | 96 |
|
93 | 97 | # Copy completions if they exist |
94 | 98 | $completionsPath = Join-Path $tmpDir "completions" |
95 | 99 | if (Test-Path $completionsPath) { |
96 | | - $targetCompletions = "$GOENV_ROOT\completions" |
| 100 | + $targetCompletions = Join-Path $GOENV_ROOT "completions" |
97 | 101 | New-Item -ItemType Directory -Path $targetCompletions -Force | Out-Null |
98 | 102 | Copy-Item -Path "$completionsPath\*" -Destination $targetCompletions -Recurse -Force -ErrorAction SilentlyContinue |
99 | 103 | } |
100 | 104 |
|
101 | 105 | Write-ColorOutput Green "goenv installed successfully!" |
| 106 | + |
| 107 | + # Remove stale goenv shim from v2 installations. |
| 108 | + # v2's goenv-rehash bakes the Cellar/libexec path into shims at creation time. |
| 109 | + # Only remove if it contains "libexec/goenv" — the v2 fingerprint. |
| 110 | + $staleShim = Join-Path (Join-Path $GOENV_ROOT "shims") "goenv" |
| 111 | + if (Test-Path $staleShim) { |
| 112 | + $shimContent = Get-Content $staleShim -Raw -ErrorAction SilentlyContinue |
| 113 | + if ($shimContent -and $shimContent -match "libexec/goenv") { |
| 114 | + Write-ColorOutput Yellow "Removing stale v2 goenv shim..." |
| 115 | + Remove-Item -Path $staleShim -Force -ErrorAction SilentlyContinue |
| 116 | + Write-ColorOutput Green "Stale shim removed" |
| 117 | + } |
| 118 | + } |
102 | 119 | } |
103 | 120 | catch { |
104 | 121 | Write-ColorOutput Red "Installation failed: $_" |
105 | 122 | exit 1 |
106 | 123 | } |
107 | 124 | finally { |
108 | | - # Cleanup |
| 125 | + # Cleanup temp directory |
109 | 126 | if (Test-Path $tmpDir) { |
110 | 127 | Remove-Item -Path $tmpDir -Recurse -Force -ErrorAction SilentlyContinue |
111 | 128 | } |
112 | 129 | } |
113 | 130 | } |
114 | 131 |
|
115 | 132 | # Auto-configure PowerShell profile |
116 | | -function Setup-PowerShellProfile { |
| 133 | +function Initialize-PowerShellProfile { |
117 | 134 | $profilePath = $PROFILE |
118 | 135 |
|
119 | 136 | # Create profile directory if it doesn't exist |
@@ -184,7 +201,7 @@ function Main { |
184 | 201 |
|
185 | 202 | $version = Get-LatestVersion |
186 | 203 | Install-Binary -Version $version -Arch $arch |
187 | | - Setup-PowerShellProfile |
| 204 | + Initialize-PowerShellProfile |
188 | 205 | Show-Instructions |
189 | 206 | } |
190 | 207 |
|
|
0 commit comments