mirror of
https://github.com/basecamp/omarchy.git
synced 2026-02-17 15:25:37 +00:00
Extract omarchy-battery-remaining command
This commit is contained in:
@@ -4,33 +4,18 @@
|
|||||||
|
|
||||||
BATTERY_THRESHOLD=10
|
BATTERY_THRESHOLD=10
|
||||||
NOTIFICATION_FLAG="/run/user/$UID/omarchy_battery_notified"
|
NOTIFICATION_FLAG="/run/user/$UID/omarchy_battery_notified"
|
||||||
|
BATTERY_LEVEL=$(omarchy-battery-remaining)
|
||||||
get_battery_percentage() {
|
BATTERY_STATE=$(upower -i $(upower -e | grep 'BAT') | grep -E "state" | awk '{print $2}')
|
||||||
upower -i "$(upower -e | grep 'BAT')" \
|
|
||||||
| awk -F: '/percentage/ {
|
|
||||||
gsub(/[%[:space:]]/, "", $2);
|
|
||||||
val=$2;
|
|
||||||
printf("%d\n", (val+0.5))
|
|
||||||
exit
|
|
||||||
}'
|
|
||||||
}
|
|
||||||
|
|
||||||
get_battery_state() {
|
|
||||||
upower -i $(upower -e | grep 'BAT') | grep -E "state" | awk '{print $2}'
|
|
||||||
}
|
|
||||||
|
|
||||||
send_notification() {
|
send_notification() {
|
||||||
notify-send -u critical " Time to recharge!" "Battery is down to ${1}%" -i battery-caution -t 30000
|
notify-send -u critical " Time to recharge!" "Battery is down to ${1}%" -i battery-caution -t 30000
|
||||||
}
|
}
|
||||||
|
|
||||||
BATTERY_LEVEL=$(get_battery_percentage)
|
if [[ $BATTERY_STATE == "discharging" && $BATTERY_LEVEL -le $BATTERY_THRESHOLD ]]; then
|
||||||
BATTERY_STATE=$(get_battery_state)
|
if [[ ! -f $NOTIFICATION_FLAG ]]; then
|
||||||
|
send_notification $BATTERY_LEVEL
|
||||||
if [[ "$BATTERY_STATE" == "discharging" && "$BATTERY_LEVEL" -le "$BATTERY_THRESHOLD" ]]; then
|
touch $NOTIFICATION_FLAG
|
||||||
if [[ ! -f "$NOTIFICATION_FLAG" ]]; then
|
|
||||||
send_notification "$BATTERY_LEVEL"
|
|
||||||
touch "$NOTIFICATION_FLAG"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
rm -f "$NOTIFICATION_FLAG"
|
rm -f $NOTIFICATION_FLAG
|
||||||
fi
|
fi
|
||||||
|
|||||||
11
bin/omarchy-battery-remaining
Executable file
11
bin/omarchy-battery-remaining
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Returns the battery percentage remaining as an integer.
|
||||||
|
|
||||||
|
upower -i $(upower -e | grep BAT) \
|
||||||
|
| awk -F: '/percentage/ {
|
||||||
|
gsub(/[%[:space:]]/, "", $2);
|
||||||
|
val=$2;
|
||||||
|
printf("%d\n", (val+0.5))
|
||||||
|
exit
|
||||||
|
}'
|
||||||
Reference in New Issue
Block a user