#! /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 "$@"