From 4ffad3ac6c5259b975650cf1aeaaecb1fd255be3 Mon Sep 17 00:00:00 2001 From: shmibs Date: Wed, 28 May 2014 08:49:01 -0700 Subject: updated calc ans can now be used to refer to the previous answer value in a calculation --- .config/herbstluftwm/calc.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to '.config/herbstluftwm') diff --git a/.config/herbstluftwm/calc.sh b/.config/herbstluftwm/calc.sh index 0f7ddfb..358f43d 100755 --- a/.config/herbstluftwm/calc.sh +++ b/.config/herbstluftwm/calc.sh @@ -8,19 +8,26 @@ e="2.7182818284590452353602874713526624977572471" while [ "$in" != "" ]; do in=$(echo "" | dmenu -q -h 18 -nb $1 -nf $2 -sb $3 -sf $4 -p "$prompt") - out=$(echo "pi=$pi; e=$e; $acc $in" | calc -p 2>&1 | tr -d "\n") - - if [ "$out" = "Missing operator" ]; then - out=$(echo "pi=$pi; e=$e; $in" | calc -p 2>&1) - fi + # replace "ans" with the previous value + in=$(echo $in | sed -e "s/ans/$acc/g") - # check for error output + out=$(echo "pi=$pi; e=$e; $acc $in" | calc -p 2>&1) + if [ "${?#0}" != "" ]; then out=$(echo "$out" | tr -d "\n") - prompt="calc: ($acc) err: $out" - else - acc=$out - prompt="calc: ($acc)" + if [ "$out" = "Missing operator" ]; then + out=$(echo "pi=$pi; e=$e; $in" | calc -p 2>&1) + if [ "${?#0}" != "" ]; then + out=$(echo "$out" | tr -d "\n") + prompt="calc: ($acc) err: $out" + else + acc=$out + prompt="calc: ($acc)" + fi + else + out=$(echo "$out" | tr -d "\n") + prompt="calc: ($acc) err: $out" + fi fi done -- cgit v1.2.3