Add gitignore option for automatic gitignore-aware file hiding#2628
Open
Olyxz16 wants to merge 8 commits into
Open
Add gitignore option for automatic gitignore-aware file hiding#2628Olyxz16 wants to merge 8 commits into
gitignore option for automatic gitignore-aware file hiding#2628Olyxz16 wants to merge 8 commits into
Conversation
added 8 commits
June 25, 2026 03:18
Add a new boolean option 'gitignore' (default false). When enabled, lf queries git check-ignore when loading directory contents inside a git worktree, and hides those files instead of using the static hiddenfiles patterns. This avoids the visual blinking caused by lf-remote IPC delays when trying to implement the same feature via on-cd hooks. Changes: - opts.go: add gitignore bool option with default false - eval.go: add toggle handler that triggers async directory reloads - nav.go: add getGitIgnored helper, file.gitIgnored flag, dir.gitWorktree state, and mutually exclusive filter logic in dir.sort() The two hiding mechanisms are mutually exclusive at the directory level: - Inside a git worktree: only gitignored files (plus .git) are hidden - Outside a git worktree: normal hiddenfiles behavior applies
Add gitignore to the Quick Reference options list and the Settings section in doc.md. Regenerate doc.txt and lf.1 via gen/doc.sh.
This change allows per-directory hiddenfiles configuration via setlocal, enabling gitignore-aware hiding through the on-load hook without blinking. Changes: - opts.go: add hiddenfiles to gLocalOpts; add getHiddenFiles() helper - eval.go: add hiddenfiles case to setLocalExpr.eval with sort/redraw - nav.go: use getHiddenFiles(dir.path) instead of gOpts.hiddenfiles - app.go: move onLoad() before d.sort() so hooks can affect sort order The on-load hook now runs synchronously before sorting, allowing it to set local options (like hiddenfiles) that affect the initial render.
Add hiddenfiles to the setlocal supported options list. Remove the gitignore documentation that was added in the previous approach. Regenerate doc.txt and lf.1 via gen/doc.sh.
- Add noSuspend flag to skip terminal suspend/resume during sync shell commands (on-load hooks), eliminating flicker and escape sequence leakage - Restructure dirChan handler: cache directory before draining server commands so addcustominfo can find files - Buffer serverChan (32) so readExpr() never blocks waiting for the main loop to receive setlocal/addcustominfo responses - Update onLoad() to toggle noSuspend around cmd.eval()
…ly on-load - Guard all sort/position/loadFile calls in setLocalExpr.eval() with !app.noSuspend to prevent double-preview-loading during the dirChan handler's server command drain loop - Run on-load only for the currently focused directory, skipping parent directories. This reduces main-loop blocking from ~110ms to ~22ms when cd'ing into deep paths, eliminating preview lag caused by blocked event processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new boolean option
gitignore(defaultfalse) that makeslfautomatically respect.gitignorerules when displaying directories inside a git worktree.Links to #2627
Motivation
Implementing gitignore-aware hiding via
lfrcconfiguration (e.g.on-cdhooks callinglf -remote) produces visible blinking/artifacts due to IPC delays. Theon-cdhook runs asynchronously, solfrenders the directory with stalehiddenfilesbefore the remote command arrives and forces a redraw. This cannot be fixed from user configuration alone.The only clean solution is to query git at directory load time, before the UI ever sees the files.
What changed
opts.gogitignore booltogOptsstruct; defaultfalseeval.gogitignore/nogitignore/gitignore!; triggers async directory reloads viaapp.nav.renew()nav.gogetGitIgnored()helper,file.gitIgnoredflag,dir.gitWorktreestate, and mutually exclusive filter logic indir.sort()doc.mdgitignoreto Quick Reference and Settings sectionsdoc.txt,lf.1gen/doc.shDesign details
The two hiding mechanisms are mutually exclusive at the directory level:
getGitIgnored()callsgit check-ignore --stdin -zonce per directory load. Only files returned by git (plus.git) are hidden. Normal dotfiles that are not ignored (e.g..bashrc) remain visible.hiddenfilesbehavior applies unchanged.When the
gitignoreoption is toggled at runtime,checkDir()detects the change and triggers an async directory reload via the existing reload infrastructure (same pattern used fordircountschanges).Complexity assessment
nav.goalready importsos/exec.git check-ignore --stdin -zcall per directory load. Negligible overhead when disabled. When enabled, batching via stdin is faster than N individualgit check-ignorecalls.$PATH. Gracefully degrades when git is not installed.Testing
go build .passesgo test ./...passesgo vet ./...cleango fmt ./...cleangen/doc.shran successfullyUsage
.git) are hidden. Normal dotfiles that are not ignored remain visible.hiddenfilesbehavior applies.:set gitignore!.