diff --git a/scripts/mkdraft.sh b/scripts/mkdraft.sh new file mode 100755 index 0000000..1ed0952 --- /dev/null +++ b/scripts/mkdraft.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -o pipefail + +if [ -z "$1" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + echo 'Usage: scripts/mkdraft.sh Title Of Your Post' + [ -z "$1" ] && exit 1 || exit +fi + +# thx https://stackoverflow.com/a/29436423 +function yes_or_no { + read -p "$* [y/N]: " yn + case $yn in + [Yy]*) return 0 ;; + *) echo "Aborted" ; return 1 ;; + esac +} + +title="$@" +path="src/posts/drafts/$(date +%F)-$(echo -n $title | tr 'A-Z' 'a-z' | tr -c '[:alnum:]' -).md" + +if [ -f $path ]; then + yes_or_no "$path already exists! Do you want to overwrite it?" || exit +fi + +cat << EOF > $path +--- +title: $title +--- +# $title +EOF + +echo "Created new draft in $path" diff --git a/src/posts/drafts/.gitignore b/src/posts/drafts/.gitignore new file mode 100644 index 0000000..e9a723a --- /dev/null +++ b/src/posts/drafts/.gitignore @@ -0,0 +1,3 @@ +* +!drafts.json +!.gitignore diff --git a/src/posts/drafts/drafts.json b/src/posts/drafts/drafts.json new file mode 100644 index 0000000..e9caa44 --- /dev/null +++ b/src/posts/drafts/drafts.json @@ -0,0 +1 @@ +{"draft": true}