From a70753364cd3949e419ea0c0a4f73619479a3594 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 15:21:50 +1000 Subject: [PATCH] platform specific shell usage --- gitcommands.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gitcommands.go b/gitcommands.go index 2dce88f8d..50c1f2a9f 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "os/exec" + "runtime" "strings" "time" @@ -111,12 +112,20 @@ func mergeGitStatusFiles(oldGitFiles, newGitFiles []GitFile) []GitFile { return result } +func platformShell() (string, string) { + if runtime.GOOS == "windows" { + return "cmd", "/c" + } + return "sh", "-c" +} + func runDirectCommand(command string) (string, error) { timeStart := time.Now() - commandLog(command) + + shell, shellArg := platformShell() cmdOut, err := exec. - Command("sh", "-c", command). + Command(shell, shellArg, command). CombinedOutput() devLog("run direct command time for command: ", command, time.Now().Sub(timeStart)) return sanitisedCommandOutput(cmdOut, err)