diff --git a/scripts/scripts/zet b/scripts/scripts/zet index 03178cf..9276519 100755 --- a/scripts/scripts/zet +++ b/scripts/scripts/zet @@ -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}" diff --git a/vim/vimrc b/vim/vimrc index 2048461..3579265 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -33,7 +33,7 @@ set smarttab set softtabstop=2 set tabstop=2 set termguicolors -set textwidth=200 +set textwidth=72 " Used with line wrapping set ttyfast " faster scrolling set undodir=~/.vim/undodir set undofile