summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-08-09 13:14:24 +1000
committerJesse Duffield <jessedduffield@gmail.com>2018-08-09 13:14:24 +1000
commit5cc34e780154bbf6bc3233fe52b60d22c87cb072 (patch)
treee41bbc8be8667543d96708e429b4b63cff3250d0
parentce8884f509b11c807a529a2118c87b007f1d7dbe (diff)
factor out platform specific logic into a struct on state
-rw-r--r--gitcommands.go11
-rw-r--r--gui.go29
2 files changed, 30 insertions, 10 deletions
diff --git a/gitcommands.go b/gitcommands.go
index 22fa4d1f3..f05e857f6 100644
--- a/gitcommands.go
+++ b/gitcommands.go
@@ -8,7 +8,6 @@ import (
"os"
"os/exec"
"regexp"
- "runtime"
"strings"
"time"
@@ -118,20 +117,12 @@ func mergeGitStatusFiles(oldGitFiles, newGitFiles []GitFile) []GitFile {
return result
}
-func platformShell() (string, string) {
- if runtime.GOOS == "windows" {
- return "cmd", "/c"
- }
- return "bash", "-c"
-}
-
func runDirectCommand(command string) (string, error) {
timeStart := time.Now()
commandLog(command)
- shell, shellArg := platformShell()
cmdOut, err := exec.
- Command(shell, shellArg, command).
+ Command(state.Platform.shell, state.Platform.shellArg, command).
CombinedOutput()
devLog("run direct command time for command: ", command, time.Now().Sub(timeStart))
return sanitisedCommandOutput(cmdOut, err)
diff --git a/gui.go b/gui.go
index fecbe8f6c..93b6d21dd 100644
--- a/gui.go
+++ b/gui.go
@@ -5,6 +5,7 @@ import (
// "io"
// "io/ioutil"
+ "runtime"
"strings"
"time"
@@ -28,6 +29,7 @@ type stateType struct {
ConflictTop bool
Conflicts []conflict
EditHistory *stack.Stack
+ Platform platform
}
type conflict struct {
@@ -45,6 +47,33 @@ var state = stateType{
ConflictTop: true,
Conflicts: make([]conflict, 0),
EditHistory: stack.New(),
+ Platform: getPlatform(),
+}
+
+type platform struct {
+ os string
+ shell string
+ shellArg string
+ escapedQuote string
+}
+
+func getPlatform() platform {
+ switch runtime.GOOS {
+ case "windows":
+ return platform{
+ os: "windows",
+ shell: "cmd",
+ shellArg: "/c",
+ escapedQuote: "\\\"",
+ }
+ default:
+ return platform{
+ os: runtime.GOOS,
+ shell: "bash",
+ shellArg: "-c",
+ escapedQuote: "\"",
+ }
+ }
}
func scrollUpMain(g *gocui.Gui, v *gocui.View) error {