Skip to content

Commit 0bc3f3d

Browse files
committed
fix(activate): strictly use forward slashes and colons for POSIX scripts on Windows
1 parent 7588ab3 commit 0bc3f3d

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

cmd/10.deactivate.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func generateDeactivationScript(shellType string) string {
113113

114114
// generatePosixDeactivationScript generates a POSIX-compatible deactivation script.
115115
func generatePosixDeactivationScript(shimsDir string) string {
116+
posixShimsDir := shimsDir
117+
if runtime.GOOS == "windows" {
118+
posixShimsDir = filepath.ToSlash(posixShimsDir)
119+
}
116120
return fmt.Sprintf(`# UniRTM deactivation script
117121
# 1. Clean up shims and injected paths from PATH
118122
_unirtm_clean_path() {
@@ -142,7 +146,7 @@ done
142146
# 4. Remove hook if present
143147
unset -f unirtm
144148
unset -f _unirtm_hook
145-
`, shimsDir)
149+
`, posixShimsDir)
146150
}
147151

148152
// generateFishDeactivationScript generates a fish shell deactivation script.

internal/service/activation.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,24 @@ func (m *ActivationManager) generatePosixScript(config ActivationConfig) (*Activ
279279
// Add shims directory to PATH
280280
sb.WriteString("# Add UniRTM shims to PATH\n")
281281
// Clean up existing shims from PATH to avoid duplicates
282-
sb.WriteString(fmt.Sprintf(`export PATH="%s:$(echo "$PATH" | sed -E 's|%s:?||g' | sed 's|:$||')"`+"\n", config.ShimsDir, config.ShimsDir))
282+
posixShimsDir := config.ShimsDir
283+
if runtime.GOOS == "windows" {
284+
posixShimsDir = filepath.ToSlash(posixShimsDir)
285+
}
286+
sb.WriteString(fmt.Sprintf(`export PATH="%s:$(echo "$PATH" | sed -E 's|%s:?||g' | sed 's|:$||')"`+"\n", posixShimsDir, posixShimsDir))
283287
sb.WriteString("\n")
284288
} else if len(config.InjectedPaths) > 0 {
285289
// PATH mode activation
286290
sb.WriteString("# UniRTM PATH mode activation\n")
287-
injectedPath := strings.Join(config.InjectedPaths, string(os.PathListSeparator))
291+
var posixPaths []string
292+
for _, p := range config.InjectedPaths {
293+
if runtime.GOOS == "windows" {
294+
posixPaths = append(posixPaths, filepath.ToSlash(p))
295+
} else {
296+
posixPaths = append(posixPaths, p)
297+
}
298+
}
299+
injectedPath := strings.Join(posixPaths, ":")
288300

289301
// Use UNIRTM_PATH to track injected paths.
290302
// Use a shell loop to filter out existing UNIRTM-managed entries from PATH,

internal/service/auto_activation.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,16 @@ func (m *AutoActivationManager) generatePosixDeactivation(sb *strings.Builder, s
418418
sb.WriteString("\n")
419419
} else {
420420
// No previous path known, clean up what we injected
421-
shimsDir := m.activationManager.shimsDir
421+
posixShimsDir := m.activationManager.shimsDir
422+
if runtime.GOOS == "windows" {
423+
posixShimsDir = filepath.ToSlash(posixShimsDir)
424+
}
422425
sb.WriteString("# Clean up UniRTM paths from PATH\n")
423426
sb.WriteString("_unirtm_clean_path() {\n")
424427
sb.WriteString(" local result=\"\"\n")
425428
sb.WriteString(" local IFS=:\n")
426429
sb.WriteString(" for _p in $PATH; do\n")
427-
sb.WriteString(fmt.Sprintf(" case \":$UNIRTM_PATH:%s:\" in\n", shimsDir))
430+
sb.WriteString(fmt.Sprintf(" case \":$UNIRTM_PATH:%s:\" in\n", posixShimsDir))
428431
sb.WriteString(" *\":$_p:\"*) ;;\n")
429432
sb.WriteString(" *) result=\"${result:+$result:}$_p\" ;;\n")
430433
sb.WriteString(" esac\n")

0 commit comments

Comments
 (0)