nnote/arbnote

38 lines
1014 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
NOTETYPE="${1-}"
if [[ "$NOTETYPE" == "daily" ]]; then
DATESTRING="$(date +%Y/%m/%d)"
NOTEHEAD=" for $DATESTRING"
elif [[ "$NOTETYPE" == "monthly" ]]; then
DATESTRING="$(date +%Y/%m)"
NOTEHEAD=" for $DATESTRING"
elif [[ "$NOTETYPE" == "yearly" ]]; then
DATESTRING="$(date +%Y)"
NOTEHEAD=" for $DATESTRING"
elif [[ "$NOTETYPE" == "global" ]]; then
DATESTRING=""
NOTEHEAD=""
else
echo "usage: arbnote <type> [notename]"
echo " create or edit a note"
echo " arbnote --help"
echo " print this help"
echo " "
echo "arbnote requires a type: daily, monthly, yearly, or global"
echo "if not provided, type is used for notename, too"
exit 1
fi
NOTESDIR="${NOTESDIR:-$HOME/Notes}"
NOTEKIND="$1"
NOTENAME="${2:-$NOTETYPE}"
DATEDIR="$NOTESDIR/$DATESTRING"
mkdir -p "$DATEDIR"
NOTEPATH="$DATEDIR/$NOTENAME"
echo "$NOTEPATH"
if ! [ -f "$NOTEPATH" ]; then
printf "$NOTENAME$NOTEHEAD\n---\n\n" > "$NOTEPATH"
fi
$EDITOR "$NOTEPATH"