Skip to content

Instantly share code, notes, and snippets.

@snOm3ad
Last active October 18, 2022 02:31
Show Gist options
  • Save snOm3ad/66223476ef159dbbed51b062950f3217 to your computer and use it in GitHub Desktop.
Save snOm3ad/66223476ef159dbbed51b062950f3217 to your computer and use it in GitHub Desktop.
automatic `.md` file creator with zettelkasten format.
#!/bin/bash
# $# - arguments passed to the program.
while [[ $# -gt 0 ]]
do
case "$1" in
-h|--help)
PROG_NAME=$(basename "$0")
echo "$PROG_NAME"
echo "A note creator for zettelkasten format."
echo " "
echo "USAGE:"
echo " $PROG_NAME NOTE_NAME [OPTIONS]"
echo " "
echo "OPTIONS:"
echo " -h, --help show brief help"
echo " -o, --open open file immediately"
exit 0
;;
-o|--open)
ATTACH=1
shift
;;
*)
[ -z "$NOTE_NAME" ] && NOTE_NAME="$1"
shift
;;
esac
done
if [ -n "$NOTE_NAME" ]; then
FILENAME="$(date '+%Y%m%d%H%M') $NOTE_NAME.md"
# create new file if it doesn't exist.
[[ -f "$FILENAME" ]] || touch "$FILENAME"
# try to open the file using default editor
[ -n "$ATTACH" -a -n "$EDITOR" ] && $EDITOR "$FILENAME"
if [ $? == 0 ]; then
exit 0
else
[ -z "$ATTACH" ] && exit 0
echo "[ERROR]: unable to open file, no default editor (\$EDITOR is not set)."
exit 1
fi
else
echo "[ERROR]: missing file name, use 'zettel --help' for usage."
exit 1
fi
@snOm3ad
Copy link
Author

snOm3ad commented Oct 18, 2022

If you use some sort of note taking app, you know that most of them have the Zettelkasten functionality which is just a fancy way of saying they prepend today's date to the beginning of the file. Sometimes you get ideas when you're in your remote machine somewhere up the wazoo and for whatever reason the pain of having to switch from your comfortable terminal to the GUI hurts you more than that Johnny Cash song. So you eventually find yourself wishing there was a way to just generate these files programmatically from your terminal, but without having the extra burden of installing a TUI or some other note taking engine which is meant to replace the app.

Well this is what this is meant to be, a simple script that does the job, enjoy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment