Add verbosity flag to runk

This commit is contained in:
Akemi Izuko 2023-12-23 20:13:55 -07:00
parent 2bb22480ef
commit 14daf13a79
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC

View file

@ -58,6 +58,7 @@ viw() {
} }
# Ronald's Universal Number Kounter, standardized syntax for unix calculators # Ronald's Universal Number Kounter, standardized syntax for unix calculators
# Use v as the first argument for verbosity/debugging
# Syntax features: # Syntax features:
# ^ and ** both work for exponentiation # ^ and ** both work for exponentiation
# log() is base 10 # log() is base 10
@ -65,6 +66,12 @@ viw() {
# log2() is base 2 # log2() is base 2
# Careful when changing order or sed might sed itself! # Careful when changing order or sed might sed itself!
runk() { runk() {
local -i is_verbose=0
if [[ "$1" == v ]]; then
shift 1
is_verbose=1
fi
local calc_ver="$(echo "$@" | sed \ local calc_ver="$(echo "$@" | sed \
-e 's#log2(\([^)]\+\))#(log(\1)/log(2))#g' \ -e 's#log2(\([^)]\+\))#(log(\1)/log(2))#g' \
)" )"
@ -80,6 +87,16 @@ runk() {
-e 's#log2(\([^)]\+\))#(l(\1)/l(2))#g' \ -e 's#log2(\([^)]\+\))#(l(\1)/l(2))#g' \
)" )"
if [[ $is_verbose -eq 1 ]]; then
if command -v calc &>/dev/null; then
printf 'Using calc: %s\n' "$calc_ver"
elif command -v python3 &>/dev/null; then
printf 'Using python: %s\n' "$py_ver"
else
printf 'Using benchcalc: %s\n' "$bc_ver"
fi
fi
if command -v calc &>/dev/null; then if command -v calc &>/dev/null; then
calc "$calc_ver" calc "$calc_ver"
elif command -v python3 &>/dev/null; then elif command -v python3 &>/dev/null; then