Commit | Line | Data |
---|---|---|
ab32f98a SK |
1 | #! /bin/bash |
2 | ||
3 | set -euo pipefail | |
4 | ||
2200de00 SK |
5 | DEFAULT_BASE="$HOME/doc/drafts/adhoc" |
6 | ||
ab32f98a SK |
7 | bar() { |
8 | local -r len="${1:-80}" # 1st arg or 80. | |
9 | local -r char="${2:--}" # 2nd arg or a dash. | |
10 | ||
11 | seq -s "$char" "$len" | sed -E 's/[0-9]+//g' | |
12 | } | |
13 | ||
14 | main() { | |
2200de00 SK |
15 | local -r base="${1:-$DEFAULT_BASE}" |
16 | ||
ab32f98a SK |
17 | local -r title_given='Untitled' |
18 | local -r title_lower=$(echo "$title_given" | tr '[:upper:]' '[:lower:]') | |
19 | local -r title_lower_dashed=$(echo "$title_lower" | sed 's/\s\+/-/g') | |
ab32f98a SK |
20 | local -r timestamp="$(date --iso-8601=ns)" |
21 | local -r file="${base}/${timestamp}--${title_lower_dashed}.md" | |
22 | ||
23 | mkdir -p "$base" | |
24 | if [[ ! -a "$file" ]] | |
25 | then | |
26 | touch "$file" | |
27 | { | |
28 | echo "$title_given" | |
29 | bar 80 '=' | |
30 | echo "started: $timestamp" | |
31 | printf '\n\n' | |
32 | } > "$file" | |
33 | fi | |
34 | echo "$file" | |
35 | } | |
36 | ||
37 | main "$@" |