mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-27 02:51:44 -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 {
|
func (env *Shell) HasFiles(pattern string) bool {
|
||||||
defer env.Trace(time.Now(), pattern)
|
defer env.Trace(time.Now(), pattern)
|
||||||
|
|
||||||
cwd := env.Pwd()
|
cwd := env.Pwd()
|
||||||
fileSystem := os.DirFS(cwd)
|
fileSystem := os.DirFS(cwd)
|
||||||
matches, err := fs.Glob(fileSystem, pattern)
|
|
||||||
|
matches, err := fs.ReadDir(fileSystem, ".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
env.Error(err)
|
env.Error(err)
|
||||||
env.Debug("false")
|
env.Debug("false")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pattern = strings.ToLower(pattern)
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
file, err := fs.Stat(fileSystem, match)
|
if match.IsDir() {
|
||||||
if err != nil || file.IsDir() {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")
|
env.Debug("true")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
env.Debug("false")
|
env.Debug("false")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue