pushd and popd for ctrlp.vim

also delegate more stuff
This commit is contained in:
Leonora Tindall 2024-08-29 14:24:17 -05:00
parent fee04030e6
commit 5b956b096c
7 changed files with 98 additions and 75 deletions

36
README
View File

@ -1,20 +1,44 @@
nnote: nora's notes
----
provides four notemaking scripts: dnote, mnote, ynote, gnote
provides a script, nnote, to quickly make notes in a simple hierarchy
provides four quick aliases: dnote, mnote, ynote, gnote
installation
----
set $NOTESDIR or use ~/Notes
clone this repo to ~NOTESDIR/bin
symlink dnote, mnote, ynote, gnote to your path like
optionally, set $NOTESDIR.
if you don't do this, nnote will use ~/Notes
$ ln -s "$NOTESDIR/bin/dnote" "$HOME/.bin/dnote"
then, install the scripts
option 1: clone this repo to ~$NOTESDIR/bin
then symlink dnote, mnote, ynote, gnote to your PATH like
$ ln -s "$NOTESDIR/bin/dnote" "$HOME/.bin/dnote"
option 2: clone this repo (wherever you like) and either
a) add that directory to your PATH, or
b) copy or symlink these scripts into your PATH
usage
----
use dnote for daily notes, mnote for monthly, ynote for yearly, gnote for global
when you call nnote, you give it a note type (daily/monthly/yearly/global)
and, optionally, a note name, which can include spaces with or without quoting.
nnote will:
- create the appropriate note directory,
- make the note if it doesn't exist,
- cd into $NOTESDIR so your CtrlP.vim or whatever will work,
- and then open the note in $EDITOR
when the editor closes it'll cd back to where you were.
aliases are provided:
- dnote for daily notes
- mnote for monthly
- ynote for yearly
- gnote for global
you can enter different names but by default those are the note names too
the file hierarchy is very simple, for instance:
- $NOTESDIR

37
arbnote
View File

@ -1,37 +0,0 @@
#!/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"

13
dnote
View File

@ -1,14 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "${1-}" == "--help" ] || [ "${1-}" == "-h" ]; then
echo "usage: dnote [notename]"
echo " create a daily note in \$NOTESDIR/year/month/day"
echo " default \$NOTESDIR is ~/Notes"
echo " yours is ${NOTESDIR-$HOME/Notes}"
echo " default notename is 'daily'"
echo " multi word notenames accepted without quotes."
if [ -f "$(which nnote)" ]; then
NNOTE="$(which nnote)"
else
NOTEBIN="$( dirname -- "$( readlink -f -- "$0"; )"; )"
$NOTEBIN/arbnote daily "$*"
NNOTE="$NOTEBIN/nnote"
fi
$NNOTE daily "$*"

13
gnote
View File

@ -1,14 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "${1-}" == "--help" ] || [ "${1-}" == "-h" ]; then
echo "usage: gnote [notename]"
echo " create a note in \$NOTESDIR/"
echo " default \$NOTESDIR is ~/Notes"
echo " yours is ${NOTESDIR-$HOME/Notes}"
echo " default notename is 'global'"
echo " multi word notenames accepted without quotes."
if [ -f "$(which nnote)" ]; then
NNOTE="$(which nnote)"
else
NOTEBIN="$( dirname -- "$( readlink -f -- "$0"; )"; )"
$NOTEBIN/arbnote global "$*"
NNOTE="$NOTEBIN/nnote"
fi
$NNOTE global "$*"

13
mnote
View File

@ -1,14 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "${1-}" == "--help" ] || [ "${1-}" == "-h" ]; then
echo "usage: mnote [notename]"
echo " create a monthly note in \$NOTESDIR/year/month"
echo " default \$NOTESDIR is ~/Notes"
echo " yours is ${NOTESDIR-$HOME/Notes}"
echo " default notename is 'monthly'"
echo " multi word notenames accepted without quotes."
if [ -f "$(which nnote)" ]; then
NNOTE="$(which nnote)"
else
NOTEBIN="$( dirname -- "$( readlink -f -- "$0"; )"; )"
$NOTEBIN/arbnote monthly "$*"
NNOTE="$NOTEBIN/nnote"
fi
$NNOTE monthly "$*"

48
nnote Executable file
View File

@ -0,0 +1,48 @@
#!/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
$EDITOR "$NOTEPATH"
popd > /dev/null
fi

13
ynote
View File

@ -1,14 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "${1-}" == "--help" ] || [ "${1-}" == "-h" ]; then
echo "usage: ynote [notename]"
echo " create a yearly note in \$NOTESDIR/year"
echo " default \$NOTESDIR is ~/Notes"
echo " yours is ${NOTESDIR-$HOME/Notes}"
echo " default notename is 'yearly'"
echo " multi word notenames accepted without quotes."
if [ -f "$(which nnote)" ]; then
NNOTE="$(which nnote)"
else
NOTEBIN="$( dirname -- "$( readlink -f -- "$0"; )"; )"
$NOTEBIN/arbnote yearly "$*"
NNOTE="$NOTEBIN/nnote"
fi
$NNOTE yearly "$*"