11# goenv installer script for Windows PowerShell
2- # Usage: iwr -useb https://raw.githubusercontent.com/go-nv/goenv/master /install.ps1 | iex
2+ # Usage: iwr -useb https://raw.githubusercontent.com/go-nv/goenv/main /install.ps1 | iex
33
44$ErrorActionPreference = " Stop"
55
@@ -112,7 +112,44 @@ function Install-Binary {
112112 }
113113}
114114
115- # Print setup instructions
115+ # Auto-configure PowerShell profile
116+ function Setup-PowerShellProfile {
117+ $profilePath = $PROFILE
118+
119+ # Create profile directory if it doesn't exist
120+ $profileDir = Split-Path - Parent $profilePath
121+ if (-not (Test-Path $profileDir )) {
122+ New-Item - ItemType Directory - Path $profileDir - Force | Out-Null
123+ }
124+
125+ # Create profile file if it doesn't exist
126+ if (-not (Test-Path $profilePath )) {
127+ New-Item - ItemType File - Path $profilePath - Force | Out-Null
128+ }
129+
130+ # Check if goenv is already configured
131+ $profileContent = Get-Content $profilePath - Raw - ErrorAction SilentlyContinue
132+ if ($profileContent -and $profileContent -match " goenv init" ) {
133+ Write-ColorOutput Green " goenv is already configured in $profilePath "
134+ return
135+ }
136+
137+ # Add goenv configuration with comment marker
138+ Write-ColorOutput Yellow " Adding goenv configuration to $profilePath ..."
139+
140+ $goenvConfig = @"
141+
142+ # goenv - Go version manager (auto-configured by installer)
143+ `$ env:GOENV_ROOT = "`$ HOME\.goenv"
144+ `$ env:PATH = "`$ env:GOENV_ROOT\bin;`$ env:PATH"
145+ & goenv init - | Invoke-Expression
146+ "@
147+
148+ Add-Content - Path $profilePath - Value $goenvConfig
149+ Write-ColorOutput Green " PowerShell profile configured successfully!"
150+ }
151+
152+ # Print setup completion message
116153function Show-Instructions {
117154 $profilePath = $PROFILE
118155
@@ -121,22 +158,11 @@ function Show-Instructions {
121158 Write-ColorOutput Green " Installation complete!"
122159 Write-ColorOutput Green " =============================================="
123160 Write-Output " "
124- Write-ColorOutput Yellow " Add the following to your PowerShell profile:"
125- Write-Output " $profilePath "
126- Write-Output " "
127- Write-Output " `$ env:GOENV_ROOT = \" `$ HOME\.goenv\" "
128- Write-Output " `$ env:PATH = \" `$ env:GOENV_ROOT\bin;`$ env:PATH\" "
129- Write-Output " & goenv init - | Invoke-Expression"
130- Write-Output " "
131- Write-ColorOutput Yellow " Quick setup command (copy and paste):"
132- Write-Output " "
133- Write-Output " `$ env:GOENV_ROOT = \" `$ HOME\.goenv\" "
134- Write-Output " `$ env:PATH = \" `$ env:GOENV_ROOT\bin;`$ env:PATH\" "
135- Write-Output " & goenv init - | Invoke-Expression"
136- Write-Output " "
137- Write-ColorOutput Yellow " Then reload your profile:"
161+ Write-ColorOutput Yellow " To start using goenv, reload your profile:"
138162 Write-Output " . `$ PROFILE"
139163 Write-Output " "
164+ Write-ColorOutput Yellow " Or restart your PowerShell session"
165+ Write-Output " "
140166 Write-ColorOutput Yellow " Quick start:"
141167 Write-Output " goenv install 1.22.0 # Install Go 1.22.0"
142168 Write-Output " goenv global 1.22.0 # Set as default"
@@ -158,6 +184,7 @@ function Main {
158184
159185 $version = Get-LatestVersion
160186 Install-Binary - Version $version - Arch $arch
187+ Setup- PowerShellProfile
161188 Show-Instructions
162189}
163190
0 commit comments