@@ -14,7 +14,7 @@ import (
1414
1515// Version information
1616const (
17- VERSION = "0.1.3 "
17+ VERSION = "0.1.4 "
1818)
1919
2020// Embed the shell integration scripts into the binary at compile time
@@ -310,11 +310,41 @@ func setupZshIntegration(homeDir string) {
310310
311311// setupPowerShellIntegration sets up integration for PowerShell
312312func setupPowerShellIntegration (homeDir string ) {
313+ // Get the correct profile path by asking PowerShell itself
314+ // We use Split-Path to get just the directory, then append the standard profile name
315+ profilePathCmd := exec .Command ("powershell" , "-NoProfile" , "-Command" ,
316+ "$profileDir = Split-Path $PROFILE; Write-Output (Join-Path $profileDir 'Microsoft.PowerShell_profile.ps1')" )
317+ profilePathBytes , err := profilePathCmd .Output ()
318+ if err != nil {
319+ fmt .Fprintf (os .Stderr , "Error getting PowerShell profile path: %v\n " , err )
320+ // Fall back to default path
321+ profilePathBytes = []byte (filepath .Join (homeDir , "Documents" , "WindowsPowerShell" , "Microsoft.PowerShell_profile.ps1" ))
322+ }
323+ profilePath := strings .TrimSpace (string (profilePathBytes ))
324+ profileDir := filepath .Dir (profilePath )
325+
326+ // Get the correct module path by asking PowerShell for PSModulePath
327+ modulePathCmd := exec .Command ("powershell" , "-NoProfile" , "-Command" ,
328+ "Write-Output ($env:PSModulePath -split ';' | Where-Object { $_ -like \" *$env:USERPROFILE*\" } | Select-Object -First 1)" )
329+ modulePathBytes , err := modulePathCmd .Output ()
330+ var modulesRoot string
331+ if err != nil {
332+ fmt .Fprintf (os .Stderr , "Error getting PowerShell module path: %v\n " , err )
333+ // Fall back to using the same directory as the profile
334+ modulesRoot = filepath .Join (profileDir , "Modules" )
335+ } else {
336+ modulesRoot = strings .TrimSpace (string (modulePathBytes ))
337+ // If we didn't get a path (perhaps no user module path exists yet), fall back
338+ if modulesRoot == "" {
339+ modulesRoot = filepath .Join (profileDir , "Modules" )
340+ }
341+ }
342+
313343 // Create PowerShell modules directory
314- modulesDir := filepath .Join (homeDir , "Documents" , "WindowsPowerShell" , "Modules" , "uve" )
315- err : = os .MkdirAll (modulesDir , 0755 )
344+ modulesDir := filepath .Join (modulesRoot , "uve" )
345+ err = os .MkdirAll (modulesDir , 0755 )
316346 if err != nil {
317- fmt .Fprintf (os .Stderr , "Error creating PowerShell modules directory: %v\n " , err )
347+ fmt .Fprintf (os .Stderr , "Error creating PowerShell modules directory at %s : %v\n " , modulesDir , err )
318348 os .Exit (1 )
319349 }
320350
@@ -326,10 +356,6 @@ func setupPowerShellIntegration(homeDir string) {
326356 os .Exit (1 )
327357 }
328358
329- // Create or update PowerShell profile
330- profileDir := filepath .Join (homeDir , "Documents" , "WindowsPowerShell" )
331- profilePath := filepath .Join (profileDir , "Microsoft.PowerShell_profile.ps1" )
332-
333359 // Ensure profile directory exists
334360 err = os .MkdirAll (profileDir , 0755 )
335361 if err != nil {
@@ -343,6 +369,7 @@ func setupPowerShellIntegration(homeDir string) {
343369 if err == nil {
344370 if strings .Contains (string (profileContent ), "Import-Module uve" ) {
345371 fmt .Println ("PowerShell integration already set up in profile" )
372+ fmt .Printf ("Profile location: %s\n " , profilePath )
346373 fmt .Println ("To use UVE in the current session, run: Import-Module uve" )
347374 return
348375 }
@@ -363,6 +390,8 @@ func setupPowerShellIntegration(homeDir string) {
363390 }
364391
365392 fmt .Println ("PowerShell integration set up successfully." )
393+ fmt .Printf ("Profile location: %s\n " , profilePath )
394+ fmt .Printf ("Module location: %s\n " , modulesDir )
366395 fmt .Println ("To use UVE in the current session, run: Import-Module uve" )
367396 fmt .Println ("UVE will be automatically available in new PowerShell sessions." )
368397}
0 commit comments