Skip to content

Add --max-shown and --tree-filter for tree output#1203

Open
Shonas301 wants to merge 2 commits into
lsd-rs:mainfrom
Shonas301:pr/tree-output-controls
Open

Add --max-shown and --tree-filter for tree output#1203
Shonas301 wants to merge 2 commits into
lsd-rs:mainfrom
Shonas301:pr/tree-output-controls

Conversation

@Shonas301
Copy link
Copy Markdown

Two flags I found myself wanting while manually walking large trees with --tree.

  • --max-shown N — caps the number of items rendered at each depth. Items past
    the cap roll up into a ... and N more summary line. Applies per depth level,
    so a deep tree doesn't explode. This covers the feature request in Feature request: limit number of files shown per directory in tree mode #1188
    (there it's proposed as --max-items; I called it --max-shown since the
    cap applies per depth level, not globally — happy to rename if you prefer
    the --max-items spelling).
  • --tree-filter <glob> — filter files by a glob pattern. Directories always
    pass (otherwise you can't walk into them), files have to match. E.g.
    --tree-filter '*.rs'.

They combine: --tree-filter '*.rs' --max-shown 2 shows at most 2 matching
files per directory plus the "... and N more" tail.

Man page and config sample updates included.

Closes #1188.


TODO

  • Use cargo fmt
  • Add necessary tests
  • Update README (if applicable)
  • Update config sample file in doc/samples (if applicable)
  • Update icon sample file in doc/samples (if applicable)
  • Update color sample file in doc/samples (if applicable)
  • Update man page at lsd/doc/lsd.md (if applicable)

* Add --max-shown and --tree-filter flags

Changes made:
- add MaxShown flag (src/flags/max_shown.rs) with Configurable trait impl
- add TreeFilter flag (src/flags/tree_filter.rs) mirroring IgnoreGlobs pattern
- wire both flags into CLI (app.rs), Config (config_file.rs), and Flags (flags.rs)
- implement tree filter logic in inner_display_tree: dirs always pass, files matched by glob
- implement max_shown truncation with "... and N more" summary row
- filter applied before truncation as per spec
- add unit tests in max_shown.rs and tree_filter.rs
- add integration tests in display.rs for truncation, filter, and combined behavior

* Simplify tree filter and reduce allocations

Changes made:
- extract create_glob/create_glob_set to shared glob_helpers module
- replace .cloned().collect() with Vec<&Meta> to avoid deep-cloning subtrees
- inline has_summary as truncated > 0
- minor cleanup of summary row cell construction
@Shonas301 Shonas301 requested a review from zwpaper as a code owner April 13, 2026 13:09
@Shonas301
Copy link
Copy Markdown
Author

Sorry for the cold-open on this and #1202 - hope that's alright. Np if you want me to make changes on either, or if you don't think they belong in upstream.

I have one more change I can PR following this that kind of ties it all together visually, lmk if it or any combination of the 3 are wanted! (picture attached)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: limit number of files shown per directory in tree mode

1 participant