#!/bin/bash set -euo pipefail usage() { printf "usage: %s [-c] [-p] [-h] [-x]\n" "$0" printf "\n" printf "Prompts for a one-line message, and appends to twtxt.txt. Optionally,\n" printf "commits and pushes a new post.\n" printf "\n" printf "Flags:\n" printf " -c Commit\n" printf " -p Push after commit (requires -c)\n" printf " -x Enable trace (set -x)\n" printf " -h Print (this) help message and exit\n" } commit=0 # commit or not, use -c to enable push=0 # push after committing while getopts cphx name do case "$name" in c) commit=1 ;; p) push=1 ;; x) set -x ;; h) usage "$0" exit 0 ;; ?) usage "$0" exit 1 ;; esac done if (( $commit == 0 )) && (( $push == 1 )) ; then printf "$0: -p (push) required -c (commit)\n" exit 1 fi printf "Type in your message, and finish by pressing Enter:\n" read msg printf "%s\t%s\n" "$(date -Im)" "${msg}" >> site/twtxt.txt if (( $commit == 1 )) ; then msgprefix="${msg:0:20}" git add site/twtxt.txt git commit -m "twtxt: new post (${msgprefix}...)" fi (( $push == 1 )) && git push