diff --git a/src/environment/shell.go b/src/environment/shell.go index 8e00e56d..1d491c55 100644 --- a/src/environment/shell.go +++ b/src/environment/shell.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "io/fs" "io/ioutil" "log" "net/http" @@ -138,7 +139,7 @@ type Environment interface { DirMatchesOneOf(dir string, regexes []string) bool HasCommand(command string) bool FileContent(file string) string - FolderList(path string) []string + LsDir(path string) []fs.DirEntry RunCommand(command string, args ...string) (string, error) RunShellCommand(shell, command string) string ExecutionTime() float64 @@ -410,21 +411,21 @@ func (env *ShellEnvironment) FileContent(file string) string { return fileContent } -func (env *ShellEnvironment) FolderList(path string) []string { - defer env.trace(time.Now(), "FolderList", path) - content, err := os.ReadDir(path) +func (env *ShellEnvironment) LsDir(path string) []fs.DirEntry { + defer env.trace(time.Now(), "LsDir", path) + entries, err := os.ReadDir(path) if err != nil { - env.log(Error, "FolderList", err.Error()) + env.log(Error, "LsDir", err.Error()) return nil } - var folderNames []string - for _, s := range content { - if s.IsDir() { - folderNames = append(folderNames, s.Name()) + env.debugF("LsDir", func() string { + var entriesStr string + for _, entry := range entries { + entriesStr += entry.Name() + "\n" } - } - env.debugF("FolderList", func() string { return strings.Join(folderNames, ",") }) - return folderNames + return entriesStr + }) + return entries } func (env *ShellEnvironment) PathSeparator() string { diff --git a/src/mock/environment.go b/src/mock/environment.go index 822a90fa..589b8a69 100644 --- a/src/mock/environment.go +++ b/src/mock/environment.go @@ -1,6 +1,7 @@ package mock import ( + "io/fs" "oh-my-posh/environment" "github.com/distatus/battery" @@ -46,9 +47,9 @@ func (env *MockedEnvironment) FileContent(file string) string { return args.String(0) } -func (env *MockedEnvironment) FolderList(path string) []string { +func (env *MockedEnvironment) LsDir(path string) []fs.DirEntry { args := env.Called(path) - return args.Get(0).([]string) + return args.Get(0).([]fs.DirEntry) } func (env *MockedEnvironment) PathSeparator() string { diff --git a/src/segments/git.go b/src/segments/git.go index 431ff8cd..1f4c7b82 100644 --- a/src/segments/git.go +++ b/src/segments/git.go @@ -495,8 +495,14 @@ func (g *Git) getWorktreeContext() int { if !g.env.HasFolder(g.gitRootFolder + "/worktrees") { return 0 } - worktreeFolders := g.env.FolderList(g.gitRootFolder + "/worktrees") - return len(worktreeFolders) + worktreeFolders := g.env.LsDir(g.gitRootFolder + "/worktrees") + var count int + for _, folder := range worktreeFolders { + if folder.IsDir() { + count++ + } + } + return count } func (g *Git) getOriginURL(upstream string) string {