#!/bin/sh ## ok: a minimal command runner and build tool # by Case Duckworth -- released to the public domain QUIET=false NORUN=false FBUILD=false OKFILE=./ok FRFILE=.fr _usage() { exec >&2 cat<&2 '* %s\n' "$*" $NORUN || "$@" || exit $((100 + $?)) } quietly() { "$@" >/dev/null 2>&1; } frun() { cut -f2- <"$FRFILE" | while read -r line do eval "$line" done } fr() { # fr < GOAL JOB DEPS... # recommended: use a heredoc :>"$FRFILE" while read -r goal job deps do eval set -- "$deps" if buildp "$goal" "$@" then printf '%s\t%s %s\n' \ "$goal" \ "$job" "$(echo "$deps"|sed 's/--.*//')" \ >>"$FRFILE" fi done } while getopts hqnxBf:C: OPT do case "$OPT" in (h) _usage ;; (q) QUIET=true ;; (x) set -x ;; (n) NORUN=true ;; (B) FBUILD=true ;; (f) OKFILE="$OPTARG" ;; (C) cd "$OPTARG" || exit 2 ;; (*) _usage 1 ;; esac done shift $((OPTIND - 1)) . "$OKFILE" || exit 3 test -z "$1" && default for target do if grep -q "$target" "$FRFILE" then eval "$(grep "$target" "$FRFILE" | cut -f2-)" else "$target" fi done