aboutsummaryrefslogtreecommitdiffstats
path: root/.config/herbstluftwm/calc.sh
diff options
context:
space:
mode:
authorshmibs <shmibs@gmail.com>2014-05-28 08:49:01 -0700
committershmibs <shmibs@gmail.com>2014-05-28 08:49:01 -0700
commit4ffad3ac6c5259b975650cf1aeaaecb1fd255be3 (patch)
treefd37665dad2eca4484f0978e6cf6750dea0cd348 /.config/herbstluftwm/calc.sh
parentf1ca9695d1d00955003af3c44b5aac5fbcce970b (diff)
downloaddotfiles-4ffad3ac6c5259b975650cf1aeaaecb1fd255be3.tar.gz
updated calc
ans can now be used to refer to the previous answer value in a calculation
Diffstat (limited to '.config/herbstluftwm/calc.sh')
-rwxr-xr-x.config/herbstluftwm/calc.sh27
1 files changed, 17 insertions, 10 deletions
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