Skip to content

Commit 73965e6

Browse files
fixed powershell profile/module path issue
1 parent d3a7009 commit 73965e6

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

main.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// Version information
1616
const (
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
312312
func 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
}

package-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# Configuration
4-
VERSION="0.1.3"
4+
VERSION="0.1.4"
55
PACKAGE="main.go"
66
BINARY_NAME="uve-bin"
77
PLATFORMS=("windows/amd64" "linux/amd64" "darwin/amd64" "darwin/arm64")

0 commit comments

Comments
 (0)