Taking hidden files parameter into account in windows (#1684)

* taking hidden files parameter into account

* Updated doc and removed irelevant linter comment

* fixed doc

* fixed doc again

* Defaulted to empty string on windows
This commit is contained in:
Catalin Ancutei authored and GitHub committed 2024-06-17 19:03:29 +10:00
1 parent 2d3cc97f78
commit 791341990c
5 files changed
+30 -14

No files matched your search

+3 -3
View File
@@ -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.
-1
View File
@@ -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
+1 -1
View File
@@ -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
+5 -4
View File
@@ -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 (
+21 -5
View File
@@ -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 {