1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-15 11:56:37 +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
commit 1a4cf84b58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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