mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
feat(shell): make hasfiles support case insensitive filenames in pattern
This commit is contained in:
parent
d6a3345b99
commit
64da68a3b8
|
@ -425,22 +425,36 @@ func (env *Shell) Pwd() string {
|
|||
|
||||
func (env *Shell) HasFiles(pattern string) bool {
|
||||
defer env.Trace(time.Now(), pattern)
|
||||
|
||||
cwd := env.Pwd()
|
||||
fileSystem := os.DirFS(cwd)
|
||||
matches, err := fs.Glob(fileSystem, pattern)
|
||||
|
||||
matches, err := fs.ReadDir(fileSystem, ".")
|
||||
if err != nil {
|
||||
env.Error(err)
|
||||
env.Debug("false")
|
||||
return false
|
||||
}
|
||||
|
||||
pattern = strings.ToLower(pattern)
|
||||
for _, match := range matches {
|
||||
file, err := fs.Stat(fileSystem, match)
|
||||
if err != nil || file.IsDir() {
|
||||
if match.IsDir() {
|
||||
continue
|
||||
}
|
||||
env.Debug("true")
|
||||
return true
|
||||
|
||||
matchFileName, err := filepath.Match(pattern, strings.ToLower(match.Name()))
|
||||
if err != nil {
|
||||
env.Error(err)
|
||||
env.Debug("false")
|
||||
return false
|
||||
}
|
||||
|
||||
if matchFileName {
|
||||
env.Debug("true")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
env.Debug("false")
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue