summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2021-10-25 18:46:59 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2021-10-25 18:46:59 +0900
commitedac9820b54d8db7ef667c2d79b9e526c625f59d (patch)
treeb944a2fadaff91b633c130cb3390527a9870321e
parent84a47f71029992fe804e506a6128643bffbb598c (diff)
Cache cygpath result
No need to repeatedly run cygpath process because $SHELL never changes.
-rw-r--r--src/util/util_windows.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/util/util_windows.go b/src/util/util_windows.go
index 8a85a072..9ac062af 100644
--- a/src/util/util_windows.go
+++ b/src/util/util_windows.go
@@ -7,19 +7,28 @@ import (
"os"
"os/exec"
"strings"
+ "sync/atomic"
"syscall"
)
+var shellPath atomic.Value
+
// ExecCommand executes the given command with $SHELL
func ExecCommand(command string, setpgid bool) *exec.Cmd {
- shell := os.Getenv("SHELL")
- if len(shell) == 0 {
- shell = "cmd"
- } else if strings.Contains(shell, "/") {
- out, err := exec.Command("cygpath", "-w", shell).Output()
- if err == nil {
- shell = strings.Trim(string(out), "\n")
+ var shell string
+ if cached := shellPath.Load(); cached != nil {
+ shell = cached.(string)
+ } else {
+ shell = os.Getenv("SHELL")
+ if len(shell) == 0 {
+ shell = "cmd"
+ } else if strings.Contains(shell, "/") {
+ out, err := exec.Command("cygpath", "-w", shell).Output()
+ if err == nil {
+ shell = strings.Trim(string(out), "\n")
+ }
}
+ shellPath.Store(shell)
}
return ExecCommandWith(shell, command, setpgid)
}