Skip to content

fix: rtk ls summary line inflates pipe count #482

@FlorianBruniaux

Description

@FlorianBruniaux

Problem

rtk ls <dir> | wc -l returns a count inflated by 2 (blank line + summary line) because the 📊 summary is always written to stdout.

rtk ls src/ | wc -l   # returns N+2 (wrong)
ls src/ | wc -l        # returns N (correct)

This breaks any script that pipes rtk ls to count files or process entries.

Unix Convention

Metadata/summary goes to stderr or is suppressed when stdout is not a TTY. RTK already uses this pattern in gain.rs via std::io::IsTerminal.

ls itself does this — no summary when piped.

Proposed Fix

Suppress the 📊 summary line when stdout is piped (not a TTY). Show it only in interactive mode.

Changes to src/ls.rs

  • Add use std::io::IsTerminal;
  • Split compact_ls() return value into (entries: String, summary: String) tuple
  • In run(): always print entries, only print summary when stdout().is_terminal()
  • Track only what is actually sent to stdout for rtk gain accuracy

Verification

# Pipe mode — should NOT show summary
rtk ls src/ | wc -l

# TTY mode — should show summary
rtk ls src/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions