Skip to content
Myr

Cache cygpath result

Before adoption: this commit came in with the history the project adopted, so no landing records it.

No need to repeatedly run cygpath process because $SHELL never changes.

authored by Junegunn Choi · committed by Junegunn Choi · parent 84a47f7 · Browse files · 1 file+16 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+16 added−7 removed

  • other:+16 added−7 removed

1 file+16 added−7 removed

modified:src/util/util_windows.go+16 added-7 removed
5 unmodified lines
6 "fmt"7 "os"8 "os/exec"9 "strings"10 "sync/atomic"11 "syscall"12)1314var shellPath atomic.Value1516// ExecCommand executes the given command with $SHELL17func ExecCommand(command string, setpgid bool) *exec.Cmd {18 var shell string19 if cached := shellPath.Load(); cached != nil {20 shell = cached.(string)21 } else {15 shell := os.Getenv("SHELL")16 if len(shell) == 0 {17 shell = "cmd"18 } else if strings.Contains(shell, "/") {19 out, err := exec.Command("cygpath", "-w", shell).Output()20 if err == nil {21 shell = strings.Trim(string(out), "\n")22 shell = os.Getenv("SHELL")23 if len(shell) == 0 {24 shell = "cmd"25 } else if strings.Contains(shell, "/") {26 out, err := exec.Command("cygpath", "-w", shell).Output()27 if err == nil {28 shell = strings.Trim(string(out), "\n")29 }30 }31 shellPath.Store(shell)32 }33 return ExecCommandWith(shell, command, setpgid)34}35
48 unmodified lines