From: Siraaj Khandkar Date: Thu, 30 Mar 2023 17:26:21 +0000 (-0400) Subject: Add new adhoc draft script X-Git-Url: https://git.xandkar.net/?p=khome.git;a=commitdiff_plain;h=ab32f98a2226acf25dfa0288468a23070f1877ca Add new adhoc draft script --- diff --git a/home/.xbindkeysrc b/home/.xbindkeysrc index d3b25fe..c9c1d51 100644 --- a/home/.xbindkeysrc +++ b/home/.xbindkeysrc @@ -155,6 +155,8 @@ Mod4 + i #"cd ~/doc/drafts && drafts_prepend && gvim -c NERDTreeFind drafts.md" "cd ~/doc/drafts && drafts_prepend && gvim drafts.md" + Mod4 + d + Shift +"cd ~/doc/drafts && gvim $(draft)" Mod4 + d "cd ~/doc/notes && notes_prepend && gvim -c NERDTreeFind notes.md" Mod4 + n diff --git a/home/bin/draft b/home/bin/draft new file mode 100755 index 0000000..de7b6e4 --- /dev/null +++ b/home/bin/draft @@ -0,0 +1,34 @@ +#! /bin/bash + +set -euo pipefail + +bar() { + local -r len="${1:-80}" # 1st arg or 80. + local -r char="${2:--}" # 2nd arg or a dash. + + seq -s "$char" "$len" | sed -E 's/[0-9]+//g' +} + +main() { + local -r title_given='Untitled' + local -r title_lower=$(echo "$title_given" | tr '[:upper:]' '[:lower:]') + local -r title_lower_dashed=$(echo "$title_lower" | sed 's/\s\+/-/g') + local -r base="${HOME}/doc/drafts/adhoc" + local -r timestamp="$(date --iso-8601=ns)" + local -r file="${base}/${timestamp}--${title_lower_dashed}.md" + + mkdir -p "$base" + if [[ ! -a "$file" ]] + then + touch "$file" + { + echo "$title_given" + bar 80 '=' + echo "started: $timestamp" + printf '\n\n' + } > "$file" + fi + echo "$file" +} + +main "$@"