Skip to content

fix: handle tail rewrites with read tail-lines#412

Open
gula00 wants to merge 1 commit intortk-ai:masterfrom
gula00:fix/tail-rewrite-lines
Open

fix: handle tail rewrites with read tail-lines#412
gula00 wants to merge 1 commit intortk-ai:masterfrom
gula00:fix/tail-rewrite-lines

Conversation

@gula00
Copy link

@gula00 gula00 commented Mar 8, 2026

Closes #407

Summary

This PR fixes the tail -N rewrite regression where:

  • rtk rewrite "tail -20 <file>" incorrectly produced rtk read -20 <file>
  • the rewritten command then failed because rtk read does not accept that flag format

What changed

  • Added tail-specific rewrite handling in src/discover/registry.rs:

    • tail -N <file> -> rtk read <file> --tail-lines N
    • tail -n N <file> -> rtk read <file> --tail-lines N
    • tail --lines=N <file> -> rtk read <file> --tail-lines N
    • tail --lines N <file> -> rtk read <file> --tail-lines N
  • Added --tail-lines support to rtk read in:

    • src/main.rs
    • src/read.rs
  • Made --tail-lines and --max-lines mutually exclusive

  • Kept unsupported tail forms (e.g. tail -c) as no-rewrite fallback for safety

Validation

  • Added unit tests for rewrite mappings and read tail behavior

  • Ran:

    • cargo fmt --all
    • cargo clippy --all-targets
    • cargo test --all

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.

tail -N fails when rewritten to rtk read

1 participant