Skip to content

feat: add --preview / -p flag for content preview#21

Open
hai-pilgrim wants to merge 2 commits intomarksverdhei:mainfrom
hai-pilgrim:feat/preview-flag
Open

feat: add --preview / -p flag for content preview#21
hai-pilgrim wants to merge 2 commits intomarksverdhei:mainfrom
hai-pilgrim:feat/preview-flag

Conversation

@hai-pilgrim
Copy link
Copy Markdown

Summary

Closes #6

Adds --preview / -p flag that prints a content snippet to stderr before the hat animation, so you can see what the file contains at a glance:

Text files — first 8 lines + total line count:

  ── preview: notes.txt ──
  Meeting agenda:
  1. Q3 roadmap
  ...
  [47 lines total]

Audio files — ID3/FLAC/OGG tags via ffprobe:

  ── preview: recording.mp3 ──
  Title: Q3 Planning Call
  Artist: Zoom Recording
  Album: Work Recordings
  Duration: 42:17

Images — dimensions, colour mode, key EXIF fields:

  ── preview: IMG_4521.jpg ──
  Size: 4032x3024  Mode: RGB
  Make: Apple
  Model: iPhone 15 Pro
  DateTime: 2024:03:15 14:22:05

Preview output is stderr-only — stdout (the suggested name) is unchanged for scripting. Works alongside --quiet, --batch, and --dry-run.

Test plan

  • bats test.sh — 44/44 tests pass (6 new preview tests)
  • Manual: hat --preview --dry-run some-file.txt

Audio files were previously skipped as unreadable binaries. This adds:
- `is_audio()` detection via magic bytes (ID3, RIFF/WAVE, fLaC, OggS,
  ADTS, M4A ftyp box) with extension fallback
- Audio metadata extraction via `ffprobe`: title, artist, album, genre,
  year, duration, bitrate, codec, sample rate
- `build_user_content()` audio mode passes rich metadata as text context
  so the LLM can suggest a name based on embedded tags
- 13 new bats tests covering detection, metadata, and end-to-end naming
- README updated with audio formats and ffprobe optional dependency

Closes marksverdhei#19
Closes marksverdhei#6

Before the hat animation runs, --preview prints a content snippet to
stderr so you know what the file contains without opening it:

- Text files: first 8 lines + total line count
- Audio files: title, artist, album, duration from ffprobe tags
- Images: dimensions, colour mode, key EXIF fields (Make, Model, DateTime)

The preview goes to stderr only, so stdout output (the suggested name)
is unaffected for scripting. Adds 6 new bats tests (44 total).

Example output:
  ── preview: interview-recording.mp3 ──
  Title: Q3 Planning Call
  Artist: Zoom Recording
  Duration: 42:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File content preview - text / image / audio?

2 participants