From 14daf13a79b5dcd424973813759e755ac6b1856b Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sat, 23 Dec 2023 20:13:55 -0700 Subject: [PATCH] Add verbosity flag to runk --- bash/.bash_functions | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bash/.bash_functions b/bash/.bash_functions index f8b4bcc..2ccacb3 100644 --- a/bash/.bash_functions +++ b/bash/.bash_functions @@ -58,6 +58,7 @@ viw() { } # Ronald's Universal Number Kounter, standardized syntax for unix calculators +# Use v as the first argument for verbosity/debugging # Syntax features: # ^ and ** both work for exponentiation # log() is base 10 @@ -65,6 +66,12 @@ viw() { # log2() is base 2 # Careful when changing order or sed might sed itself! runk() { + local -i is_verbose=0 + if [[ "$1" == v ]]; then + shift 1 + is_verbose=1 + fi + local calc_ver="$(echo "$@" | sed \ -e 's#log2(\([^)]\+\))#(log(\1)/log(2))#g' \ )" @@ -80,6 +87,16 @@ runk() { -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 calc "$calc_ver" elif command -v python3 &>/dev/null; then