Skip to content

fix(rewrite): pass ls -O / -@ / -e through unchanged (#1627) - #1640

Closed
officialasishkumar wants to merge 1 commit into
rtk-ai:masterfrom
officialasishkumar:fix/rewrite-preserve-ls-metadata-1627
Closed

officialasishkumar wants to merge 1 commit into
rtk-ai:masterfrom
officialasishkumar:fix/rewrite-preserve-ls-metadata-1627

Conversation

@officialasishkumar

Copy link
Copy Markdown

Summary

The rtk `ls` filter compresses listings to a `name size` form and strips extra columns. macOS-only `ls` flags exist precisely to surface those metadata columns:

  • `-O` — BSD file flags (`uchg`, etc.)
  • `-@` — extended attributes (`com.apple.provenance`, `com.apple.quarantine`, ...)
  • `-e` — ACL entries

Rewriting those invocations silently drops the data the user is asking for and breaks real diagnostic workflows. The reporter's example: chasing a `com.apple.provenance` xattr blocking writes — `ls -lO` returned just `name size`, hiding the `@` indicator and BSD-flags column entirely.

This change skips the rewrite whenever any `O`, `@`, or `e` short-flag character appears in argv (including clusters like `-lO`, `-lOe`, `-l@e`, or as separate tokens `-O -@ -e`). Plain `ls` / `ls -l` / `ls -la` are unaffected — those are the cases the listing-compression filter was built for.

Behavior

Before:
```
$ rtk rewrite 'ls -lO some/dir'
rtk ls -lO some/dir # rewritten — filter strips the -O column
```

After:
```
$ rtk rewrite 'ls -lO some/dir'
$ echo $?
1 # no rewrite, hook lets the original ls run
$ rtk rewrite 'ls -la some/dir'
rtk ls -la some/dir # plain listing still compressed (unchanged)
```

Notes

  • Mirrors the existing `rtk gh` carve-out for `--json`/`--jq`/`--template` (fix: passthrough --json/--jq/--template flags in all gh subcommands #196): the rewrite is conditional on argv when the rtk filter would corrupt the user's intent.
  • Pure-string flag detection (no shell parsing) — splits on whitespace, looks at tokens that start with one `-` and aren't `--`, then checks for `O`/`@`/`e`. `--color`, `--all`, `-- file` separators, etc. are explicitly excluded.
  • New helper `has_ls_metadata_flag` is unit-tested directly to pin the boundary cases.

Test plan

  • New unit tests cover `-O`, `-@`, `-e`, mixed clusters `-lO@e`, separated tokens `-O -@ -e`, and the negative cases (`ls`, `ls -l`, `ls -la`, `ls --color=auto`, `ls -- some/dir`).
  • Manual repro: `rtk rewrite 'ls -lO some/dir'` → no rewrite (exit 1); `rtk rewrite 'ls -la some/dir'` → `rtk ls -la some/dir` (still rewritten).
  • `cargo fmt --all && cargo test --all` passes (1693 tests).

Closes #1627

The rtk ls filter compresses listings to a "name size" form and strips
extra columns. macOS-only ls flags -O (BSD file flags), -@ (extended
attributes), and -e (ACL entries) exist precisely to surface those
metadata columns; rewriting them silently dropped the data the user was
asking for and broke real diagnostic workflows (the reporter's repro:
chasing a com.apple.provenance xattr with ls -lO returned just `name
size`).

Skip the rewrite whenever any -O / -@ / -e short-flag character appears
in argv (including clusters like -lO, -lOe, -l@e). Plain ls / -l / -la
are unaffected.

Closes rtk-ai#1627
@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot rtk-release-bot Bot added the stale label Sep 3, 2026
@rtk-release-bot

Copy link
Copy Markdown
Contributor

Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you!

@rtk-release-bot rtk-release-bot Bot closed this Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: rtk ls rewrite silently drops -O / -@ / -e metadata columns, blocking macOS file-flag/xattr/ACL diagnostics

1 participant