Skip to content

Commit d68b7f5

Browse files
committed
fix(activate): use os.PathListSeparator for PowerShell scripts to support Linux/macOS pwsh
1 parent fc7d485 commit d68b7f5

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

cmd/10.deactivate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ func generatePowerShellDeactivationScript(shimsDir string) string {
184184
# 1. Clean up PATH
185185
$unirtmPaths = @()
186186
if ($env:UNIRTM_PATH) {
187-
$unirtmPaths = $env:UNIRTM_PATH -split ';'
187+
$unirtmPaths = $env:UNIRTM_PATH -split '%c'
188188
}
189189
$shimsDir = "%s"
190-
$env:PATH = ($env:PATH -split ';' | Where-Object { $unirtmPaths -notcontains $_ -and $_ -ne $shimsDir }) -join ';'
190+
$env:PATH = ($env:PATH -split '%c' | Where-Object { $unirtmPaths -notcontains $_ -and $_ -ne $shimsDir }) -join '%c'
191191
192192
# 2. Unset environment variables
193193
Remove-Item Env:\UNIRTM_PATH -ErrorAction SilentlyContinue
@@ -201,5 +201,5 @@ Get-ChildItem Env: | Where-Object { $_.Name -match '^UNIRTM_.*_VERSION$' } | For
201201
202202
# 4. Remove hook
203203
if (Test-Path Function:\unirtm) { Remove-Item Function:\unirtm }
204-
`, shimsDir)
204+
`, os.PathListSeparator, shimsDir, os.PathListSeparator, os.PathListSeparator)
205205
}

internal/service/activation.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func (m *ActivationManager) generatePowerShellScript(config ActivationConfig) (*
481481
shimsDir = filepath.FromSlash(shimsDir)
482482
}
483483
sb.WriteString(fmt.Sprintf("$shimsDir = \"%s\"\n", shimsDir))
484-
sb.WriteString("$env:PATH = \"$shimsDir;\" + (($env:PATH -split ';') | Where-Object { $_ -ne $shimsDir } -join ';')\n")
484+
sb.WriteString(fmt.Sprintf("$env:PATH = \"$shimsDir%c\" + (($env:PATH -split '%c') | Where-Object { $_ -ne $shimsDir } -join '%c')\n", os.PathListSeparator, os.PathListSeparator, os.PathListSeparator))
485485
sb.WriteString("\n")
486486
} else if len(config.InjectedPaths) > 0 {
487487
// PATH mode activation
@@ -494,10 +494,10 @@ func (m *ActivationManager) generatePowerShellScript(config ActivationConfig) (*
494494
}
495495
paths = append(paths, path)
496496
}
497-
injectedPath := strings.Join(paths, ";")
498-
sb.WriteString(fmt.Sprintf("$unirtmPaths = \"%s\" -split ';'\n", injectedPath))
499-
sb.WriteString("$env:UNIRTM_PATH = $unirtmPaths -join ';'\n")
500-
sb.WriteString("$env:PATH = ($env:UNIRTM_PATH + ';' + (($env:PATH -split ';') | Where-Object { $unirtmPaths -notcontains $_ } -join ';'))\n")
497+
injectedPath := strings.Join(paths, string(os.PathListSeparator))
498+
sb.WriteString(fmt.Sprintf("$unirtmPaths = \"%s\" -split '%c'\n", injectedPath, os.PathListSeparator))
499+
sb.WriteString(fmt.Sprintf("$env:UNIRTM_PATH = $unirtmPaths -join '%c'\n", os.PathListSeparator))
500+
sb.WriteString(fmt.Sprintf("$env:PATH = ($env:UNIRTM_PATH + '%c' + (($env:PATH -split '%c') | Where-Object { $unirtmPaths -notcontains $_ } -join '%c'))\n", os.PathListSeparator, os.PathListSeparator, os.PathListSeparator))
501501
sb.WriteString("\n")
502502
}
503503

internal/service/auto_activation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,9 @@ func (m *AutoActivationManager) generatePowerShellDeactivation(sb *strings.Build
518518
}
519519
sb.WriteString("# Clean up UniRTM paths from PATH\n")
520520
sb.WriteString("$unirtmPaths = @()\n")
521-
sb.WriteString("if ($env:UNIRTM_PATH) { $unirtmPaths = $env:UNIRTM_PATH -split ';' }\n")
521+
sb.WriteString(fmt.Sprintf("if ($env:UNIRTM_PATH) { $unirtmPaths = $env:UNIRTM_PATH -split '%c' }\n", os.PathListSeparator))
522522
sb.WriteString(fmt.Sprintf("$shimsDir = \"%s\"\n", shimsDir))
523-
sb.WriteString("$env:PATH = ($env:PATH -split ';' | Where-Object { $unirtmPaths -notcontains $_ -and $_ -ne $shimsDir }) -join ';'\n")
523+
sb.WriteString(fmt.Sprintf("$env:PATH = ($env:PATH -split '%c' | Where-Object { $unirtmPaths -notcontains $_ -and $_ -ne $shimsDir }) -join '%c'\n", os.PathListSeparator, os.PathListSeparator))
524524
sb.WriteString("\n")
525525
}
526526

0 commit comments

Comments
 (0)