diff --git a/doc.md b/doc.md index d84e7bd4..89ec42bc 100644 --- a/doc.md +++ b/doc.md @@ -158,7 +158,7 @@ The following options can be used to customize the behavior of lf: globfilter bool (default false) globsearch bool (default false) hidden bool (default false) - hiddenfiles []string (default '.*') + hiddenfiles []string (default '.*' for Unix and '' for Windows) hidecursorinactive bool (default false) history bool (default true) icons bool (default false) @@ -765,9 +765,9 @@ Otherwise, these characters are interpreted as they are. Show hidden files. On Unix systems, hidden files are determined by the value of `hiddenfiles`. -On Windows, only files with hidden attributes are considered hidden files. +On Windows, files with hidden attributes are also considered hidden files. -## hiddenfiles ([]string) (default `.*`) +## hiddenfiles ([]string) (default `.*` for Unix and `` for Windows) List of hidden file glob patterns. Patterns can be given as relative or absolute paths. diff --git a/nav.go b/nav.go index 0a16cfbb..438b8b0a 100644 --- a/nav.go +++ b/nav.go @@ -751,7 +751,6 @@ func (nav *nav) previewLoop(ui *ui) { } } -//lint:ignore U1000 This function is not used on Windows func matchPattern(pattern, name, path string) bool { s := name diff --git a/opts.go b/opts.go index 035de65b..171c5d83 100644 --- a/opts.go +++ b/opts.go @@ -235,7 +235,7 @@ func init() { gOpts.truncatechar = "~" gOpts.truncatepct = 100 gOpts.ratios = []int{1, 2, 3} - gOpts.hiddenfiles = []string{".*"} + gOpts.hiddenfiles = gDefaultHiddenFiles gOpts.history = true gOpts.info = nil gOpts.ruler = nil diff --git a/os.go b/os.go index 962bb418..3171a070 100644 --- a/os.go +++ b/os.go @@ -24,10 +24,11 @@ var ( ) var ( - gDefaultShell = "sh" - gDefaultShellFlag = "-c" - gDefaultSocketProt = "unix" - gDefaultSocketPath string + gDefaultShell = "sh" + gDefaultShellFlag = "-c" + gDefaultSocketProt = "unix" + gDefaultSocketPath string + gDefaultHiddenFiles = []string{".*"} ) var ( diff --git a/os_windows.go b/os_windows.go index a07821fc..db9ef562 100644 --- a/os_windows.go +++ b/os_windows.go @@ -23,10 +23,11 @@ var ( var envPathExt = os.Getenv("PATHEXT") var ( - gDefaultShell = "cmd" - gDefaultShellFlag = "/c" - gDefaultSocketProt = "unix" - gDefaultSocketPath string + gDefaultShell = "cmd" + gDefaultShellFlag = "/c" + gDefaultSocketProt = "unix" + gDefaultSocketPath string + gDefaultHiddenFiles []string ) var ( @@ -181,7 +182,22 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool { if err != nil { return false } - return attrs&windows.FILE_ATTRIBUTE_HIDDEN != 0 + + if attrs&windows.FILE_ATTRIBUTE_HIDDEN != 0 { + return true + } + + hidden := false + for _, pattern := range hiddenfiles { + matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path) + if strings.HasPrefix(pattern, "!") && matched { + hidden = false + } else if matched { + hidden = true + } + } + + return hidden } func userName(f os.FileInfo) string {