#!/bin/sh # The MIT License (MIT) # # Copyright (c) 2026 pacman64 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # pa [options...] [awk expressions...] # # Print Awk evaluates and prints the results of all the expressions given. # # All expressions are evaluated and printed in a `BEGIN` block, which prevents # the usual record/line-processing mode. # # The options are, available both in single and double-dash versions # # -d, -debug show code given to `awk` on the standard error # -h, -help show this help message # -v, -verbose show an ANSI-styled banner for each command being run debug=0 verbose=0 cmd='awk' while [ $# -gt 0 ]; do case "$1" in --bignum) cmd="${cmd} --bignum"; shift ;; -d|--d|-debug|--debug) debug=1; shift ;; -h|--h|-help|--help) awk '/^# +pa /, /^$/ { gsub(/^# ?/, ""); print }' "$0" exit 0 ;; -v|--v|-verbose|--verbose) verbose=1; shift ;; --) shift; break ;; -*) printf "unsupported option '%s'\n" "$1" >&2 exit 1 ;; esac break done if [ $# -eq 0 ]; then awk '/^# +pa /, /^$/ { gsub(/^# ?/, ""); print }' "$0" >&2 exit 1 fi code="$(awk -v verbose="${verbose}" ' BEGIN { vfmt = " print \"\\x1b[7m%s\\x1b[0m\" > \"/dev/stderr\"\n" print " BEGIN {" for (i = 1; i < ARGC; i++) { if (verbose) printf(vfmt, ARGV[i]) printf(" print(%s)\n", ARGV[i]) } print " exit" print " }" exit } ' "$@")" [ "${debug}" -eq 1 ] && printf "%s\n" "${code}" >&2 ${cmd} "${code}"