fzf is a command line fuzzy finding TUI thing that gives you really fast progressive narrowing on a directory full of stuff then invokes whatever on the target. This morning’s science experiment is wrapping it in a zsh function for my nb that pops up a fuzzy finder with incremental search, or offers to start a new note in nb. If you take the New Note
option, you get a prompt for the title and can start typing. The whole thing is wrapped around nb
so I get the benefits of its autosync infrastructure, just with a search interface that is way faster for finding things.
Getting this to work with emacsclient wasn’t great, and in fact it does not work with emacsclient right now. I’ve been playing around with micro and that was great for getting this far with the experiment. Not sure I’ll keep it but one of the things I was trying to figure out when I stumbled across nb (again) was “has anyone done a TUI Notational Velocity”? I haven’t found anything like that, exactly, but it is pretty cool to me that with fzf, fd, and micro, you can get most of the way there with a zsh function.
Anyhow, I need to catch up on some stuff today.
# ~/.zsh/functions/znotes.zsh
zn() {
local notes_dir=~/notes
cd "$notes_dir" || return 1
local files
files=$(fd --type f --extension org --extension md --exclude denote . "$notes_dir") || return 1
local file
file=$( (echo "[New Note]"; echo "$files") \
| fzf --prompt="Edit or create note: " \
--preview='[[ {} == "[New Note]" ]] || bat --style=numbers --color=always --line-range=:100 {}') || return 1
if [[ "$file" == "[New Note]" ]]; then
echo -n "New note title: "
read -r title
[[ -z "$title" ]] && echo "Aborted: no title given." && return 1
nb new --title "$title"
echo "Note created. You can run \`nb list\` to see it."
else
nb edit "$file"
fi
}