tmux/.config/tmux/plugins/notes.sh

#!/usr/bin/env bash
# tmux/.config/tmux/plugins/notes.sh
# Quick scratch note in a tmux popup. Bound to prefix-N in keybindings.conf.

set -euo pipefail

NOTES_ROOT="${NOTES_ROOT:-$HOME/notes}"
today=$(date +%Y-%m-%d)
yr=${today%%-*}
mo=${today:5:2}
dir="$NOTES_ROOT/$yr/$mo"
file="$dir/$today.md"

mkdir -p "$dir"
if [[ ! -f "$file" ]]; then
  {
    printf '# %s\n\n' "$today"
    printf '## today\n\n'
    printf '## notes\n'
  } > "$file"
fi

# Open in a popup using the user's $EDITOR.
exec tmux display-popup \
  -E \
  -w 80% \
  -h 80% \
  -T " notes: $today " \
  "${EDITOR:-nvim} '+normal! G' '$file'"