script: ./now script for adding to nowpage

This commit is contained in:
Lewis Wynne 2026-05-01 01:40:14 +01:00
parent 886ce662ba
commit 7fa6e6d005

26
now Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail
if [ $# -lt 1 ]; then
echo "Usage: $0 <text>" >&2
exit 1
fi
text="$*"
date=$(date +%d/%m/%y)
file="$(dirname "$(readlink -f "$0")")/content/now.md"
awk -v date="$date" -v text="$text" '
!inserted && /^<dl>$/ {
print
print ""
print "{% update(date=\"" date "\") %}"
print text
print "{% end %}"
inserted = 1
next
}
{ print }
' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
echo "Added entry dated $date to $file"