1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-27 00:51:18 +02:00

Merge pull request #2661 from jesseduffield/cache-binary-paths

Cache binary paths
This commit is contained in:
Jesse Duffield
2023-05-23 19:19:49 +10:00
committed by GitHub

View File

@ -21,11 +21,25 @@ import (
// you call `git status` from the command line directly but no harm in playing it // you call `git status` from the command line directly but no harm in playing it
// safe. // safe.
var pathCache = map[string]string{}
func Command(name string, args ...string) *exec.Cmd { func Command(name string, args ...string) *exec.Cmd {
bin, err := safeexec.LookPath(name) path := getPath(name)
if err != nil {
bin = name return exec.Command(path, args...)
} }
return exec.Command(bin, args...) func getPath(name string) string {
if path, ok := pathCache[name]; ok {
return path
}
path, err := safeexec.LookPath(name)
if err != nil {
pathCache[name] = name
return name
}
pathCache[name] = path
return path
} }