#!/bin/sh # shellcheck source=./lib.sh . "$(dirname -- "$0")/lib.sh" mode=t while getopts tpacdsb opt; do case "$opt" in \?) abort "usage: tm read-commit [-t|-p|-a|-c|-d|-s|-b] " ;; *) mode="$opt" ;; esac done shift "$((OPTIND - 1))" [ $# -eq 1 ] || abort "usage: tm read-commit [-t|-p|-a|-c|-d|-s|-b] " script= case "$mode" in t) script='/^tree / { sub(/^tree /, ""); print }';; p) script='/^parent / { sub(/^parent /, ""); print } /^date/ { exit }';; a) script='/^author / { sub(/^author /, ""); print; exit }';; c) script='/^committer / { sub(/^committer /, ""); print; exit }';; d) script='/^date / { sub(/^date /, ""); print; exit }';; s) script='BEGIN { mode="wait" } { if (mode == "subject") { print; exit } } /^date / { mode="subject" }';; b) script='BEGIN { mode="wait" } { if (mode == "subject") { mode="body" } else if (mode == "body") { print } } /^date / { mode="subject" }';; *) abort "error: cosmic rays have corrupted the mode variable, try moving your computer into a neutrino detection center";; esac exec tm cat "$1" | awk -- "$script"