Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/discover/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,16 @@ fn rewrite_segment(seg: &str, excluded: &[String]) -> Option<String> {
return rewrite_tail_lines(cmd_part).map(|r| format!("{}{}", r, redirect_suffix));
}

// Most cat flags (-v, -A, -e, -t, -s, -b, --show-all, etc.) have different
// semantics than rtk read or no equivalent at all. Only `-n` (line numbers)
// maps correctly to `rtk read -n`. Skip rewrite for any other flag.
if cmd_part.starts_with("cat ") {
let args = cmd_part["cat ".len()..].trim_start();
if args.starts_with('-') && !args.starts_with("-n ") && !args.starts_with("-n\t") {
return None;
}
}

// Use classify_command for correct ignore/prefix handling
let rtk_equivalent = match classify_command(cmd_part) {
Classification::Supported { rtk_equivalent, .. } => {
Expand Down Expand Up @@ -1163,6 +1173,26 @@ mod tests {
);
}

#[test]
fn test_rewrite_cat_with_incompatible_flags_skipped() {
// cat flags with different semantics than rtk read — skip rewrite
assert_eq!(rewrite_command("cat -A file.cpp", &[]), None);
assert_eq!(rewrite_command("cat -v file.txt", &[]), None);
assert_eq!(rewrite_command("cat -e file.txt", &[]), None);
assert_eq!(rewrite_command("cat -t file.txt", &[]), None);
assert_eq!(rewrite_command("cat -s file.txt", &[]), None);
assert_eq!(rewrite_command("cat --show-all file.txt", &[]), None);
}

#[test]
fn test_rewrite_cat_with_compatible_flags() {
// cat -n (line numbers) maps to rtk read -n — allow rewrite
assert_eq!(
rewrite_command("cat -n file.txt", &[]),
Some("rtk read -n file.txt".into())
);
}

#[test]
fn test_rewrite_rg_pattern() {
assert_eq!(
Expand Down