mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-29 20:10:56 -08:00
feat(print): improve performance
This commit is contained in:
parent
b73ac4bdc2
commit
fdb05d8407
|
@ -365,28 +365,26 @@ func (env *ShellEnvironment) Pwd() string {
|
|||
func (env *ShellEnvironment) HasFiles(pattern string) bool {
|
||||
defer env.Trace(time.Now(), "HasFiles", pattern)
|
||||
cwd := env.Pwd()
|
||||
pattern = cwd + env.PathSeparator() + pattern
|
||||
matches, err := filepath.Glob(pattern)
|
||||
fileSystem := os.DirFS(cwd)
|
||||
matches, err := fs.Glob(fileSystem, pattern)
|
||||
if err != nil {
|
||||
env.Log(Error, "HasFiles", err.Error())
|
||||
return false
|
||||
}
|
||||
for _, match := range matches {
|
||||
f, _ := os.Stat(match)
|
||||
if f.IsDir() {
|
||||
file, err := fs.Stat(fileSystem, match)
|
||||
if err != nil || file.IsDir() {
|
||||
continue
|
||||
}
|
||||
env.Log(Debug, "HasFiles", "true")
|
||||
return true
|
||||
}
|
||||
env.Log(Debug, "HasFiles", "false")
|
||||
return false
|
||||
}
|
||||
|
||||
func (env *ShellEnvironment) HasFilesInDir(dir, pattern string) bool {
|
||||
defer env.Trace(time.Now(), "HasFilesInDir", pattern)
|
||||
pattern = dir + env.PathSeparator() + pattern
|
||||
matches, err := filepath.Glob(pattern)
|
||||
fileSystem := os.DirFS(dir)
|
||||
matches, err := fs.Glob(fileSystem, pattern)
|
||||
if err != nil {
|
||||
env.Log(Error, "HasFilesInDir", err.Error())
|
||||
return false
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
func BenchmarkInit(b *testing.B) {
|
||||
cmd := cli.RootCmd
|
||||
// needs to be a non-existing file as we panic otherwise
|
||||
cmd.SetArgs([]string{"init", "fish", "--print", "--config", "err.omp.json"})
|
||||
out := bytes.NewBufferString("")
|
||||
cmd.SetOut(out)
|
||||
|
@ -16,3 +17,15 @@ func BenchmarkInit(b *testing.B) {
|
|||
_ = cmd.Execute()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPrimary(b *testing.B) {
|
||||
cmd := cli.RootCmd
|
||||
// needs to be a non-existing file as we panic otherwise
|
||||
cmd.SetArgs([]string{"print", "primary", "--config", "err.omp.json", "--pwd", "/Users/jan/Code/oh-my-posh/src"})
|
||||
out := bytes.NewBufferString("")
|
||||
cmd.SetOut(out)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = cmd.Execute()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue