You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rtk read -n (target of the cat -n rewrite) drops carriage returns and adds a final newline #4816
The hook rewrites cat -n FILE to rtk read -n FILE. Apart from its own gutter, the output differs from cat -n in content: the CR of every CRLF line is removed, and a trailing LF is added to a file that does not end with one. Plain rtk read FILE keeps both, so only the numbered path is affected.
Environment
rtk 1.1.0 full edition, x86_64-unknown-linux-musl (same on 1.0.1); Ubuntu 24.04.5 LTS; GNU coreutils 9.4.
Steps to reproduce
mkdir -p /tmp/repro &&cd /tmp/repro
printf'a\r\nb\r\nc'> crlf.txt
rtk rewrite 'cat -n crlf.txt'# rtk read -n crlf.txt
cat -n crlf.txt | od -c
rtk read -n crlf.txt | od -c
rtk read crlf.txt | od -c # unnumbered: byte-identical to the file
Expected
cat -n (rc 0), 28 bytes: 1\ta\r\n 2\tb\r\n 3\tc, with CRs kept and no final newline.
gutter: number, space, U+2502 (3 bytes), space, where cat -n uses a right-aligned number and a TAB
Why it matters
An agent that uses numbered output to edit a CRLF file, or to check whether the last line ends with a newline, sees line endings that are not on disk. Parsers that split cat -n output on the TAB fail. CONTRIBUTING: "RTK's output must be a valid, useful subset of the original tool's output".
Notes
Measured on 1.0.1 and 1.1.0, identical.
src/cmds/system/read.rs: the numbering path builds each line with format!("{:>width$} │ {}\n", ...) over text lines, so line terminators are normalised. fix(read): make head/tail rewrites faithful to the native commands #3941 made the head/tail windows byte-faithful only "with line numbering off".
rtk read -n (the cat -n rewrite target) normalizes CRLF to LF and appends a trailing newline not present in the source file, diverging from cat -n output; fix the numbering path in read.rs to preserve original line terminators and EOF state.
📁 Relevant files
src/cmds/system/read.rs
Suggested Actions
Review src/cmds/system/read.rs numbering path using format!("{:>width$} │ {}\n", ...) — it normalizes line terminators
There are 2 open pull requests for this issue: #4828, #4872 (oldest first).
If you were about to start on it, reviewing or testing one of these helps more than another pull request: a note on which approach fits, or a test result on your setup, is welcome on the pull request itself.
Activity
rtk-wshm-sync-bot commentedon Oct 28, 2026
🔍 Automated Triage
bugmediumSummary
rtk read -n(thecat -nrewrite target) normalizes CRLF to LF and appends a trailing newline not present in the source file, diverging fromcat -noutput; fix the numbering path in read.rs to preserve original line terminators and EOF state.📁 Relevant files
src/cmds/system/read.rsSuggested Actions
Triaged automatically by wshm · This is an automated analysis, not a human review.
KuSh commentedon Oct 31, 2026
There are 2 open pull requests for this issue: #4828, #4872 (oldest first).
If you were about to start on it, reviewing or testing one of these helps more than another pull request: a note on which approach fits, or a test result on your setup, is welcome on the pull request itself.