Update zet script

This commit is contained in:
2022-01-05 20:41:06 -05:00
parent 1c18e500f4
commit 500c648c5b
2 changed files with 26 additions and 5 deletions

View File

@@ -1,13 +1,32 @@
#!/bin/sh
set -e
# Creates a new `zet` inside the public `Zettlekasten` directory.
dirname="$(isosec)"
mkdir "$ZETDIR/$dirname"
dir="$ZETDIR/$dirname"
_cmd_exists() {
command -v "$@" >/dev/null 2>&1
}
# Early out if the directory is not found.
! test -d "$ZETDIR" && echo "Can't find ${ZETDIR:-'Not Found in ENV'}" && exit 1
# Early out if `isosec` is not found.
! _cmd_exists isosec && echo "isosec not found." && exit
# Create a new directory for this note.
dir="$ZETDIR/$(isosec)"
mkdir "$dir"
# Create the readme file with the title (if supplied)
readme="$dir/README.md"
title="$*"
printf "# %s\n\n" "${title}" > "${readme}"
# Bail if the readme was not created.
! test -r "$readme" && echo "README was not created properly." && exit 1
# Auto commit the new note.
message="${title:-"Autocommit message"}"
cd "$dir"
git pull -q
@@ -15,4 +34,6 @@ git add -A "$dir"
git commit -m "$message"
git push
cd -
vi "${readme}"
# Open the note.
exec vi "${readme}"