Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taking hidden files parameter into account in windows #1684

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
26 changes: 21 additions & 5 deletions os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down