From 40fe5c073e62c5b0aa2df588a36f88328064667c Mon Sep 17 00:00:00 2001 From: Esa Jokinen Date: Wed, 7 Aug 2024 12:43:29 +0300 Subject: [PATCH] product-pricelimiter.sh print diff of price & limit If the system has bc installed, print the difference between the price and the maximum price. --- bin/product-pricelimiter.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/product-pricelimiter.sh b/bin/product-pricelimiter.sh index 18fc79f..74bf450 100755 --- a/bin/product-pricelimiter.sh +++ b/bin/product-pricelimiter.sh @@ -132,9 +132,19 @@ lower=$(printf "%s\n%s" "$price" "$maxprice" | sort -g | head -1) if [ "$lower" = "$price" ]; then echo -ne "\033[0;32mGood to buy! " echo -e "The price (#$n in \"$selector\") is now $price €\033[0m" + if command -v bc &> /dev/null; then + diff=$(echo "scale=2; $maxprice - $price" | bc) + echo -ne "\033[0;32mThat is $diff € lower " + echo -e "than the max price ($maxprice €)\033[0m" + fi exit 0 else echo -ne "\033[0;33mPlease be patient! " echo -e "The price (#$n in \"$selector\") is still $price €\033[0m" + if command -v bc &> /dev/null; then + diff=$(echo "scale=2; $price - $maxprice" | bc) + echo -ne "\033[0;33mThat is $diff € higher " + echo -e "than the max price ($maxprice €)\033[0m" + fi exit 2 fi