More tools for note-selecting
Sometimes I want to select a markdown note from the shell for further work. Maybe I want to launch an LLM with the note or I want to edit the note from within a terminal to fix some bug.
Since I've discovered fzf and its preview feature I find more and more uses for it. The following shell script shows all notes that contain a given label and offers them for selection:
#!/bin/bash
# Maybe we can even get tab completion here?!
LABEL=$1; shift
find ~/bin/App-notes-htmx/notes_corion/ -maxdepth 1 -name '*.markdown' -print0 \
| xargs -0 grep -l -- " - $LABEL" \
| perl -lpe 'BEGIN{$\="\0"; s!([\s/*?])!\\$1!g }' \
| fzf --read0 --preview='cat {}'
Having not only a selection but also a custom preview makes things convenient.
Perl was useful for properly escaping the filenames. fzf has the --read0
option, but it still passes the item to the shell without escapes. Using
double quotes around the {} does not work.