Skip to content

Commit 33730c1

Browse files
authored
Windows: Insert new path after first semicolon (second position) (#204)
1 parent 19babad commit 33730c1

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

internal/terminal/terminal.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,24 @@ Prepares envs for pty/conpty.
2323
func addToPath(value string) {
2424
pathStr := os.Getenv("PATH")
2525
if runtime.GOOS == gutils.Windows {
26-
pathStr = fmt.Sprintf("%s;%s", value, pathStr)
26+
// Windows: Insert new path as second position (after first semicolon)
27+
paths := strings.Split(pathStr, ";")
28+
if len(paths) == 0 || pathStr == "" {
29+
// If PATH is empty, just set the new value
30+
pathStr = value
31+
} else if len(paths) == 1 {
32+
// If only one path exists, add new value as second
33+
pathStr = fmt.Sprintf("%s;%s", paths[0], value)
34+
} else {
35+
// Insert new value after the first path (second position)
36+
newPaths := make([]string, 0, len(paths)+1)
37+
newPaths = append(newPaths, paths[0]) // First path
38+
newPaths = append(newPaths, value) // New path as second
39+
newPaths = append(newPaths, paths[1:]...) // Rest of paths
40+
pathStr = strings.Join(newPaths, ";")
41+
}
2742
} else {
43+
// Unix/Linux: Simple prepend (original behavior)
2844
pathStr = fmt.Sprintf("%s:%s", value, pathStr)
2945
}
3046
os.Setenv("PATH", pathStr)

0 commit comments

Comments
 (0)