Skip to content

dircolors: honor TERM/COLORTERM for the built-in database - #14408

Open
Socialpranker wants to merge 1 commit into
uutils:mainfrom
Socialpranker:dircolors-term-filter
Open

dircolors: honor TERM/COLORTERM for the built-in database#14408
Socialpranker wants to merge 1 commit into
uutils:mainfrom
Socialpranker:dircolors-term-filter

Conversation

@Socialpranker

Copy link
Copy Markdown
Contributor

Without a config file, dircolors emitted the whole built-in database no
matter what terminal it was running under:

$ env -u TERM dircolors -b        # GNU
LS_COLORS='';
export LS_COLORS
$ env -u TERM dircolors -b        # uutils, before
LS_COLORS='rs=0:di=01;34:ln=01;36:...'   # the full database

Same for TERM=dumb, TERM=some-unknown-term, -c and --print-ls-colors.
The config-file path already honors TERM/COLORTERM lines; only the
built-in path did not.

The fix

The built-in database is guarded by COLORTERM ?* plus one TERM entry per
known terminal — the entries --print-database prints. generate_ls_colors
now applies that same guard before emitting anything, using the TERMS list
and the existing fnmatch helper, and returns an empty LS_COLORS when
nothing matches. -p still dumps the database unfiltered, as before.

Testing

  • New tests in tests/by-util/test_dircolors.rs covering unknown TERM,
    unset TERM, --print-ls-colors, a known TERM, COLORTERM with an
    unknown TERM, and -p staying unfiltered. Mutation-checked: neutering
    the guard fails three of them.
  • test_ls_colors gained .env("TERM", "screen"), matching its -b/-c
    siblings; it previously relied on the unfiltered output.
  • cargo test --features dircolors --test tests test_dircolors: 24 passed,
    0 failed. cargo clippy -p uu_dircolors --all-targets -- -D warnings and
    cargo fmt --check: clean.
  • Differential run against GNU coreutils 9.11 (Homebrew), 4 option sets x 8
    TERM/COLORTERM combinations plus 5 config-file cases: 8 filtering
    mismatches before, 0 after, no case regressed.

Disclosure

Prepared with AI assistance (Claude Opus 5, via Claude Code), per the AI
policy in CONTRIBUTING.md. GNU behavior above came from running the
installed binary, not from reading GPL source. All testing was run locally.

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tail/pipe-f is now passing!

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.

2 participants