51 lines
1.5 KiB
Bash
Executable File
51 lines
1.5 KiB
Bash
Executable File
#!/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: nnote <type> [notename]"
|
|
echo " create or edit a note"
|
|
echo " nnote <type> --help | -h"
|
|
echo " get help for a note type"
|
|
echo " "
|
|
echo "nnote requires a type: daily, monthly, yearly, or global"
|
|
echo "if not provided, type is used for notename, too"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "${2-}" == "--help" ] || [ "${2-}" == "-h" ]; then
|
|
echo "usage: nnote $NOTETYPE [notename]"
|
|
echo " create a $NOTETYPE note in \$NOTESDIR/$DATESTRING"
|
|
echo " default \$NOTESDIR is ~/Notes"
|
|
echo " yours is ${NOTESDIR-$HOME/Notes}"
|
|
echo " default notename is '$NOTETYPE'"
|
|
echo " multi word notenames accepted without quotes."
|
|
else
|
|
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
|
|
pushd "$NOTESDIR" > /dev/null
|
|
printf "\033]2;$NOTENAME $NOTETYPE note\a"
|
|
$EDITOR "$NOTEPATH"
|
|
printf "\033]2;\a"
|
|
popd > /dev/null
|
|
fi
|