Skip to content

feat(grep): add -L (--files-without-match) flag #380

@chaliy

Description

@chaliy

Summary

The grep builtin is missing the -L / --files-without-match flag, which prints names of files that do NOT contain any matches. This is the inverse of the existing -l flag.

Why we need this

  • GNU grep compatibility: -L is a standard GNU grep flag used in everyday shell scripts and CI pipelines (e.g., grep -rL 'TODO' src/ to find files without TODOs).
  • LLM tool usage: Coding agents frequently use grep -rL to find files that are missing expected content (missing license headers, missing imports, missing config entries). Without -L, agents must work around it with grep -rl | comm or other multi-step alternatives.
  • Trivial to implement: We already have -l (files with matches). -L is the exact inverse — print the filename when match_count == 0 instead of > 0.

Current state

The grep builtin (crates/bashkit/src/builtins/grep.rs) supports 27+ flags including -l, -r, -A/-B/-C, --include, --exclude, etc. -L is one of the few standard flags still missing.

Implementation notes

  • Add files_without_matches: bool to GrepOptions
  • Parse -L alongside -l
  • In the output phase: if files_without_matches && !file_matched, print filename
  • Add tests for stdin and multi-file cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions