diff --git a/nav.go b/nav.go index 5dee4dd..a69bb1f 100644 --- a/nav.go +++ b/nav.go @@ -554,6 +554,34 @@ func (nav *nav) previewLoop(ui *ui) { } } +func isDirty(f os.FileInfo, path string, dirtyfiles []string) bool { + dirty := false + for _, pattern := range dirtyfiles { + matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path) + if strings.HasPrefix(pattern, "!") && matched { + dirty = false + } else if matched { + dirty = true + } + } + return dirty +} + +func matchPattern(pattern, name, path string) bool { + s := name + + pattern = replaceTilde(pattern) + + if filepath.IsAbs(pattern) { + s = filepath.Join(path, name) + } + + // pattern errors are checked when 'hiddenfiles' option is set + matched, _ := filepath.Match(pattern, s) + + return matched +} + func (nav *nav) preview(path string, win *win) { reg := ®{loadTime: time.Now(), path: path} defer func() { nav.regChan <- reg }() diff --git a/os.go b/os.go index fa20879..a434d1e 100644 --- a/os.go +++ b/os.go @@ -136,19 +136,6 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool { return hidden } -func isDirty(f os.FileInfo, path string, dirtyfiles []string) bool { - dirty := false - for _, pattern := range dirtyfiles { - matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path) - if strings.HasPrefix(pattern, "!") && matched { - dirty = false - } else if matched { - dirty = true - } - } - return dirty -} - func userName(f os.FileInfo) string { if stat, ok := f.Sys().(*syscall.Stat_t); ok { if u, err := user.LookupId(fmt.Sprint(stat.Uid)); err == nil { @@ -174,21 +161,6 @@ func linkCount(f os.FileInfo) string { return "" } -func matchPattern(pattern, name, path string) bool { - s := name - - pattern = replaceTilde(pattern) - - if filepath.IsAbs(pattern) { - s = filepath.Join(path, name) - } - - // pattern errors are checked when 'hiddenfiles' option is set - matched, _ := filepath.Match(pattern, s) - - return matched -} - func errCrossDevice(err error) bool { return err.(*os.LinkError).Err.(syscall.Errno) == syscall.EXDEV }