Skip to content

Commit

Permalink
fix(devcontainer): use the default shell on Windows for
Browse files Browse the repository at this point in the history
`initializeCommand`
  • Loading branch information
pascalbreuninger committed Jan 14, 2025
1 parent 676e5b2 commit 7e57c1b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/devcontainer/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,23 @@ func runInitializeCommand(
return nil
}

shellArgs := []string{"sh", "-c"}
// According to the devcontainer spec, `initializeCommand` needs to be run on the host.
// On Windows we can't assume everyone has `sh` added to their PATH so we need to use Windows default shell (usually cmd.exe)
if runtime.GOOS == "windows" {
comSpec := os.Getenv("COMSPEC")
if comSpec != "" {
shellArgs = []string{comSpec, "/c"}
} else {
shellArgs = []string{"cmd.exe", "/c"}
}
}

for _, cmd := range config.InitializeCommand {
// should run in shell?
var args []string
if len(cmd) == 1 {
args = []string{"sh", "-c", cmd[0]}
args = []string{shellArgs[0], shellArgs[1], cmd[0]}
} else {
args = cmd
}
Expand Down

0 comments on commit 7e57c1b

Please sign in to comment.