Skip to content

feat: add zemo search command #14

@hidetzu

Description

@hidetzu

Motivation

Closes the discoverability loop for the read-only command set (ls #3, cat #4, dump #5). dump works for cross-memo search via the terminal's own search (e.g. WezTerm QuickSearch), but a dedicated search command is more efficient for the common "find lines that mention X" case and produces output (path:line:match) that pipes naturally into pickers like fzf.

Spec

zemo search <query> — print lines matching <query> across scratch and all topic files.

  • Targets:
  • Match semantics: fixed-string, case-sensitive substring match. (Regex / case-insensitive can be added later.)
  • Output format: <relative-path>:<line-number>:<line-content> per match, one per line. Path is relative to <memo> (e.g. topics/git.md:42:see also git rebase). Matches git grep -n style so output pipes into fzf, bat, etc.
  • Ordering: scratch first, then topics alphabetical (matching dump). Within a file, order by line number ascending.
  • Missing files: scratch missing → skip silently. topics/ missing → skip silently. Both missing → no output, exit 0.
  • No matches: no output, exit 1 (standard grep-like behaviour).
  • Empty query: usage error, exit 2.
  • Read-only: no git operations.

Example

$ zemo search rebase
scratch.txt:3:remember to git rebase before push
topics/git.md:12:`git rebase --interactive` to squash commits
topics/git.md:34:rebase vs merge — use rebase for feature branches

Implementation note

Implement as a Zig file walk over <memo>/scratch.txt and <memo>/topics/*.md, line-by-line fixed-string match. No git dependency, consistent with cat (#4), ls (#3), dump (#5). Memo repos are personal-scale (hundreds to low thousands of small markdown files), so a straightforward Zig walk is expected to be fast enough indefinitely.

Scope

In:

  • Resolve <memo> via ZEMO_DIR → default.
  • Walk scratch.txt + topics/*.md, fixed-string match, write path:line:content to stdout.
  • No-match → exit 1. Empty query → exit 2.

Out (separate issues):

  • --regex / -E
  • --ignore-case / -i
  • --files-only / -l
  • --topic <topic> (scope to one file)
  • --context <n> / -C
  • Color output

Acceptance criteria

  • zemo search <query> prints all matching lines across scratch.txt and topics/*.md in path:line:content format.
  • Output ordering: scratch first, then topics alphabetical, then by line number ascending.
  • Non-.md files and subdirectories under topics/ are excluded.
  • No matches → no output, exit 1.
  • Missing scratch / missing topics dir → skip silently.
  • Empty query → usage error, exit 2.
  • No git operations are performed.
  • Tests cover: matches in scratch only, matches in topics only, mixed, no matches, missing files, empty query.
  • zig build test passes.
  • README gains an entry for zemo search and an fzf integration recipe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions