Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/dippy/cli/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

COMMANDS = ["find"]

# Actions that write find's output to a file (truncating it) — same effect as a
# `> file` redirect, which Dippy already guards. The `f` prefix means "file"
# (vs. -print/-printf/-ls which write to stdout and are safe).
FILE_WRITE_ACTIONS = frozenset({"-fprint", "-fprint0", "-fprintf", "-fls"})

# Context for flags that aren't self-explanatory
FLAG_CONTEXT = {
"-ok": "execute with prompt",
Expand All @@ -36,6 +41,10 @@ def classify(ctx: HandlerContext) -> Classification:
if token == "-delete":
return Classification("ask", description=f"{base} -delete")

# -fprint/-fprintf/-fls write output to a file (truncating it)
if token in FILE_WRITE_ACTIONS:
return Classification("ask", description=f"{base} {token}")

# -exec/-execdir - extract inner command and delegate
if token in ("-exec", "-execdir"):
inner_tokens = []
Expand Down
12 changes: 8 additions & 4 deletions tests/cli/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@
("find . -printf '%f\\n'", True),
("find . -printf '%p %s\\n'", True),
("find . -ls", True),
("find . -fls /tmp/output.txt", True),
("find . -fprint /tmp/output.txt", True),
("find . -fprint0 /tmp/output.txt", True),
("find . -fprintf /tmp/output.txt '%p\\n'", True),
#
# --- Boolean operators (safe) ---
#
Expand Down Expand Up @@ -251,6 +247,14 @@
("find /tmp -name '*.cache' -delete", False),
("find . -mtime +30 -delete", False),
#
# --- -fprint/-fprintf/-fls (write output to a file, truncating it) ---
#
("find . -fprint /tmp/output.txt", False),
("find . -fprint0 /tmp/output.txt", False),
("find . -fprintf /tmp/output.txt '%p\\n'", False),
("find . -fls /tmp/output.txt", False),
("find . -name '*.py' -fprint /etc/hosts", False),
#
# --- Combinations with safe exec ---
#
("find . -name '*.py' -print -exec cat {} \\;", True),
Expand Down
Loading