ollie/scripts/s/bfg

14 lines
390 B
Bash

#!/usr/bin/env bash
# s/bfg: batch foreground query; submit prompt, wait, print result.
for _arg; do
[ "$_arg" = "-help" ] && exec "${0%/*}/b" -help
done
cmd=${0##*/}
if [ $# -eq 0 ] && [ -t 0 ]; then
printf '%s: prompt required: pass as arguments or pipe via stdin\n' "$cmd" >&2; exit 1
fi
if [ $# -eq 0 ] && ! [ -t 0 ]; then
exec "${0%/*}/b" "$(cat)"
fi
exec "${0%/*}/b" "$@"