diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2024-12-25 14:26:51 +0000 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2024-12-25 14:26:51 +0000 |
| commit | dc41873a79b32ed3d34dd7dac09c081f7472d207 (patch) | |
| tree | ba3c80c8d137263a8f346cf32853d15f75094fab /bin | |
| parent | f4c682dc6bdeebe9f0c6a20deb7092cf893791a1 (diff) | |
Change most things to symlinks instead of hardlinks
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/battery-notify.sh | 78 | ||||
| -rwxr-xr-x | bin/exit-menu.sh | 10 |
2 files changed, 76 insertions, 12 deletions
diff --git a/bin/battery-notify.sh b/bin/battery-notify.sh index ed07119..a2a6e23 100755 --- a/bin/battery-notify.sh +++ b/bin/battery-notify.sh @@ -1,14 +1,55 @@ -#!/bin/sh +#!/bin/bash last="NONE" +nid=0 -low=15 +low=10 critical=5 +polltime=2 + bat="BAT1" -while true; do +str_time () { + h=$(bc <<< "${1}/3600") + m=$(bc <<< "(${1}%3600)/60") + s=$(bc <<< "${1}%60") + + printf "%d h %02d min %02.0f sec\n" $h $m $s +} + + +calc_time_left () { + voltage_now=$(cat "$1/voltage_now") + charge_now=$(cat "$1/charge_now") + current_now=$(cat "$1/current_now") + + energy=$(bc -l <<< "($voltage_now * $charge_now) / 1000000") + power=$(bc -l <<< "($voltage_now * $current_now) / 1000000") + hours=$(bc -l <<< "$energy / $power") + + echo $(bc -l <<< "$hours * 3600") +} + + +dismiss_last_notification () { + if [[ "$nid" -ne "0" ]]; then + echo "poof" + notify-send -r $nid -t 1 " " + nid=0 + fi +} + +send_power_warning () { + time_left=$(str_time $(calc_time_left $2)) + if [[ "$nid" -ne "0" ]]; then + nid=$(notify-send -p -r $nid -u critical -t 0 "Power" "Battery $1: $3%\nRemaining: $time_left") + else + nid=$(notify-send -p -u critical -t 0 "Power" "Battery $1: $3%\nRemaining: $time_left") + fi +} +while true; do battery="/sys/class/power_supply/$bat" if [ -d $battery ]; then @@ -16,22 +57,41 @@ while true; do status=$(cat $battery/status) if [ "$last" != "FULL" ] && [ "$status" = "Full" ]; then + dismiss_last_notification notify-send "Power" "Battery is full" last="FULL" fi # If low and discharging - if [ "$last" != "LOW" ] && [ "$status" = "Discharging" ] && \ - [ $capacity -le $low ]; then - notify-send "Power" "Battery warning: $capacity%" - last=LOW + if [ "$last" != "CRITICAL" ] && [ "$status" = "Discharging" ] && [ $capacity -le $low ]; then + send_power_warning "warning" $battery $capacity + last=LOW polltime=2 fi # If critical and discharging if [ "$status" = "Discharging" ] && [ $capacity -le $critical ]; then - notify-send "Power" "Battery critical: $capacity%" + send_power_warning "critical" $battery $capacity last=CRITICAL + polltime=2 + fi + + # If charging + if [ "$status" = "Charging" ] && [ "$last" != "CHARGING" ]; then + dismiss_last_notification + notify-send "Power" "Battery charging: $capacity%" + last=CHARGING + polltime=2 + fi + + # If disharging + if [ "$status" = "Discharging" ] && [ "$last" != "LOW" ] && [ "$last" != "CRITICAL" ] && [ "$last" != "DISCHARGING" ]; then + time_left=$(str_time $(calc_time_left $battery)) + notify-send "Power" "Battery discharging: $capacity%" + last=DISCHARGING + polltime=2 fi + else + sleep 60 fi - sleep 60 + sleep $polltime done diff --git a/bin/exit-menu.sh b/bin/exit-menu.sh index b7236fe..9c9f7ab 100755 --- a/bin/exit-menu.sh +++ b/bin/exit-menu.sh @@ -1,16 +1,20 @@ #!/bin/bash -entries=" Lock\n Suspend\n Logout\n Reboot\n Shutdown" +entries=" Lock\n Suspend\n Suspend-then-Hibernate\n Hibernate\n Logout\n Reboot\n Shutdown" -selected=$(echo -e $entries|wofi --width 100 --height 185 --dmenu --cache-file /dev/null --define content_halign=center --define prompt="Exit menu" | awk '{print tolower($2)}') +selected=$(echo -e $entries|wofi --width 100 --height 212 --dmenu --cache-file /dev/null --define content_halign=center --define prompt="Exit menu" | awk '{print tolower($2)}') case $selected in lock) - hyprlock;; + swaylock;; logout) hyprctl dispatch exit;; + suspend-then-hibernate) + exec systemctl suspend-then-hibernate;; suspend) exec systemctl suspend;; + hibernate) + exec systemctl hibernate;; reboot) exec systemctl reboot;; shutdown) |
