mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-21 12:16:54 +02:00
Merge pull request #2661 from jesseduffield/cache-binary-paths
Cache binary paths
This commit is contained in:
commit
1a4cf84b58
@ -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...)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user