Add new adhoc draft script
authorSiraaj Khandkar <siraaj@khandkar.net>
Thu, 30 Mar 2023 17:26:21 +0000 (13:26 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Thu, 30 Mar 2023 17:26:21 +0000 (13:26 -0400)
home/.xbindkeysrc
home/bin/draft [new file with mode: 0755]

index d3b25fe..c9c1d51 100644 (file)
     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 (executable)
index 0000000..de7b6e4
--- /dev/null
@@ -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 "$@"
This page took 0.027076 seconds and 4 git commands to generate.