Author: Adam Evyčędo <git@apiote.xyz>
bc and dc
.config/sh/functions | 20 +++++++++++--------- .local/bin/bar_battery | 4 +++-
diff --git a/.config/sh/functions b/.config/sh/functions index bef9d8afd99bda4a08766c0c7fa61303934cdb0b..545a0b4f4be51c7d22c9c81abd554a02734361e2 100644 --- a/.config/sh/functions +++ b/.config/sh/functions @@ -1206,10 +1206,9 @@ exit 1 fi if echo "$1" | grep -Eq '^[0-9]+ml$'; then amount=$(echo "$1" | grep -Eq '^[0-9]+') - elif echo "$1" | grep -Eq '^[0-9.]+$' - then - amount=$(echo "$1" | grep -E '^([0-9]+(\.[0-9]+)?)|(\.[0-9]+)$' -o) - amount=$(echo "$amount * 1000" | bc) + elif echo "$1" | grep -Eq '^[0-9.]+$'; then + amount=$(echo "$1" | grep -Eo '^([0-9]+(\.[0-9]+)?)|(\.[0-9]+)$') + amount=$(echo "$amount 1000 * p" | dc) else case "$1" in glass) amount=100 ;; @@ -1290,11 +1289,11 @@ exit 1 fi width=$(ffprobe "$1" -show_entries stream=width -of csv=p=0 -v error -select_streams v:0) - waterWidth=$(dc -e "$width 3 /n"); + waterWidth=$(echo "$width 3 / p" | dc); height=$(ffprobe "$1" -show_entries stream=height -of csv=p=0 -v error -select_streams v:0) inkscape -w "$waterWidth" --export-filename=waterSign.png /media/nextcloud/me@cloud.apiote.xyz/Pictutes/IDs/logo/waterSign.svg waterHeight=$(ffprobe waterSign.png -show_entries stream=height -of csv=p=0 -v error -select_streams v:0) - y=$(dc -e "$height 100 - $waterHeight - n") + y=$(echo "$height 100 - $waterHeight - p" | dc) magick \( -page +0+0 "$1" \) \( -page "+100+$y" waterSign.png \) -flatten "$1.signed.jpg" rm waterSign.png } @@ -1304,9 +1303,12 @@ min_il=0 monitor-sensor --light | while read -r line do ilumination=$(echo "$line" | grep 'Light changed' | tr -s ' ' | cut -d ' ' -f 3) - brightness=$(echo "scale=2; l($ilumination - $min_il + 1) * 3" | bc -l | cut -d '.' -f1) - if [ "$brightness" -gt 100 ] - then + if [ -z "$ilumination" ]; then + continue + fi + brightness=$(echo "scale=2; l($ilumination - $min_il + 1) * 3" | fun bc | cut -d '.' -f1) + brightness=${brightness:-0} + if [ "$brightness" -gt 100 ]; then brightness=100 elif [ "$brightness" -lt 0 ]; then brightness=0 diff --git a/.local/bin/bar_battery b/.local/bin/bar_battery index 48a45a2fd5dc5b0272eadecd6ee4f78aa8e82879..bdfd13dfaeaa3b23257c12031a53d8680fea6f7a 100755 --- a/.local/bin/bar_battery +++ b/.local/bin/bar_battery @@ -1,5 +1,7 @@ #!/bin/sh +. "$HOME/.config/sh/functions" + white="#d3d7cf" yellow="#db9d3b" red="#892b30" @@ -109,7 +111,7 @@ if [ "$energy" != '-1' ] && [ "$energyE" != '-1' ] && [ "$energyF" != '-1' ] then pc_prev=$pc - pc=$(echo "$energy / ($energyF - $energyE) * 144" | bc -l | jq '.|ceil') + pc=$(echo "2 k $energy $energyF $energyE - / 144 * p" | dc | jq '.|ceil') fi if [ "$pc_prev" != "$pc" ]