42 lines
1.2 KiB
Bash
Executable File
42 lines
1.2 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: nnotes <type>"
|
|
echo " open $EDITOR (\$EDITOR) in the directory for \$type notes"
|
|
echo " nnote <type> --help | -h"
|
|
echo " get help for a note type"
|
|
echo " "
|
|
echo "nnotes requires a type: daily, monthly, yearly, or global"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "${2-}" == "--help" ] || [ "${2-}" == "-h" ]; then
|
|
echo "usage: nnotes $NOTETYPE"
|
|
echo " open $EDITOR (\$EDITOR) in \$NOTESDIR/$DATESTRING"
|
|
echo " default \$NOTESDIR is ~/Notes"
|
|
echo " yours is ${NOTESDIR-$HOME/Notes}"
|
|
else
|
|
NOTESDIR="${NOTESDIR:-$HOME/Notes}"
|
|
DATEDIR="$NOTESDIR/$DATESTRING"
|
|
mkdir -p "$DATEDIR"
|
|
echo "$DATEDIR"
|
|
pushd "$NOTESDIR" > /dev/null
|
|
printf "\033]2;$NOTETYPE note\a"
|
|
$EDITOR
|
|
printf "\033]2;\a"
|
|
popd > /dev/null
|
|
fi
|