mirror of
https://github.com/junegunn/fzf.git
synced 2025-12-11 07:01:56 +08:00
Cache cygpath result
No need to repeatedly run cygpath process because $SHELL never changes.
This commit is contained in:
@@ -7,19 +7,28 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var shellPath atomic.Value
|
||||||
|
|
||||||
// ExecCommand executes the given command with $SHELL
|
// ExecCommand executes the given command with $SHELL
|
||||||
func ExecCommand(command string, setpgid bool) *exec.Cmd {
|
func ExecCommand(command string, setpgid bool) *exec.Cmd {
|
||||||
shell := os.Getenv("SHELL")
|
var shell string
|
||||||
if len(shell) == 0 {
|
if cached := shellPath.Load(); cached != nil {
|
||||||
shell = "cmd"
|
shell = cached.(string)
|
||||||
} else if strings.Contains(shell, "/") {
|
} else {
|
||||||
out, err := exec.Command("cygpath", "-w", shell).Output()
|
shell = os.Getenv("SHELL")
|
||||||
if err == nil {
|
if len(shell) == 0 {
|
||||||
shell = strings.Trim(string(out), "\n")
|
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)
|
return ExecCommandWith(shell, command, setpgid)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user