Skip to content

Instantly share code, notes, and snippets.

@duckwork
Created March 8, 2018 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duckwork/baa6a3f0dc90cdbd9e295630e606f2cf to your computer and use it in GitHub Desktop.
Save duckwork/baa6a3f0dc90cdbd9e295630e606f2cf to your computer and use it in GitHub Desktop.
Bash script for quick blogging
#!/bin/bash
# Make a new post in acdw.net
# Usage:
# acdw.sh <group> [date]
# it uses the custom function below and dateadd,
# from dateutils.
lifeday() {
# lifeday [date]
# find out how many days old you are! looks
# for BIRTHDAY env variable, if it doesn't
# find it, it uses my birthday. the optional
# date is the day you want to calculate
# (defaults to today). it'll accept whatever
# `date -d` does.
BIRTHDAY="${BIRTHDAY:-1990-07-25}"
TIMEZONE="${TIMEZONE:--6}"
today="${@:-today}"
now="$(date -d "${today}" +%s)"
birth="$(date -d "${BIRTHDAY}" +%s)"
tzadj="$((TIMEZONE * 60 * 60))"
# tzadj=0
dysec=86400 # 60 * 60 * 24
printf '%05d' "$(( 1 + (now - birth + tzadj) / dysec ))"
}
ld="$(lifeday "$2")"
BIRTHDAY="${BIRTHDAY:-1990-07-25}"
root="$HOME/acdw.net"
file="$root/src/"${ld}".$1"
if [[ ! -e "${file}" ]]; then
printf '%% \n%% \n%% %s\n\n\n' "$(dateadd $BIRTHDAY $ld)" >$file
fi
$EDITOR $file +;
if ! grep -q -v '^%\|^$' "$file"; then
echo "Empty!"
rm "$file"
exit 1
fi
if [[ "$1" = "poem" ]]; then
sed 's/^\([ ]*[*_(A-Za-z]\)/| &/' $file > ${file}~
mv ${file}~ ${file}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment