Skip to content

fix(ls): fall back to raw output when ls binary is eza/exa/lsd (#1321)#1454

Open
pszymkowiak wants to merge 10 commits intodevelopfrom
fix/ls-eza-passthrough-fallback
Open

fix(ls): fall back to raw output when ls binary is eza/exa/lsd (#1321)#1454
pszymkowiak wants to merge 10 commits intodevelopfrom
fix/ls-eza-passthrough-fallback

Conversation

@pszymkowiak
Copy link
Copy Markdown
Collaborator

Summary

  • rtk ls returned (empty) for non-empty directories when the ls binary on PATH was eza, exa, or lsd
  • Root cause: eza uses day-first dates (22 Apr 14:30) vs POSIX month-first (Apr 22 14:30) — the regex anchor never matched, every line was silently dropped
  • Fix: track any_content_line + parse_hit in compact_ls; return a sentinel when output was present but nothing parsed, triggering a raw passthrough with a warning

Behaviour change

Scenario Before After
eza as ls on PATH (empty) eza raw output + warning ✅
Standard /bin/ls filtered output ✅ unchanged ✅
Truly empty directory (empty) unchanged ✅

No token savings on eza output (passthrough). A follow-up PR could add an eza-aware parser.

Test plan

  • 19 existing ls unit tests pass (cargo +nightly test cmds::system::ls)
  • New regression test test_compact_eza_format_returns_sentinel added
  • Manually tested with PATH=/tmp/eza-test-path:$PATH rtk ls src/ (eza symlinked as ls)
  • Truly empty directory still returns (empty)
  • cargo +nightly fmt and cargo +nightly clippy clean

Fixes #1321

🤖 Generated with Claude Code

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 22, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ pszymkowiak
✅ aeppling
❌ github-actions[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

When the `ls` binary on PATH is a modern replacement (eza, exa, lsd),
its day-first date format (22 Apr 14:30) doesn't match the POSIX regex
anchor, causing every line to fail silently and returning "(empty)" for
non-empty directories.

Track `any_content_line` and `parse_hit` in `compact_ls`. When output
lines were present but none parsed successfully, return a sentinel
(both fields empty) so the caller falls back to raw output with a
warning instead of "(empty)".

Truly empty directories and noise-filtered results are unaffected.
@pszymkowiak pszymkowiak force-pushed the fix/ls-eza-passthrough-fallback branch from f28c448 to 04e0db6 Compare April 22, 2026 14:02
@ashokgelal
Copy link
Copy Markdown

I can reproduce this as well.

In my shell, ls is provided by lsd (ls='lsd -l'), and rtk ls returns (empty) in non-empty directories for some flag combinations.

Examples that fail for me:

  • rtk ls -1A .
  • rtk ls -1 .
  • rtk ls -ltT .

Examples that work:

  • rtk ls -A .
  • rtk ls -lt .

This looks consistent with the bug fixed in this PR.

@ashokgelal
Copy link
Copy Markdown

Additional data point from my side:

Even after removing lsd from PATH and confirming ls resolves to /bin/ls, I still see this:

which ls
# /bin/ls

rtk ls -1A
# (empty)

rtk /bin/ls -1A
# <lists files correctly>

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.

4 participants