33 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/usr/bin/env bash
 | 
						|
# Low battery notifier
 | 
						|
 | 
						|
# Kill already running processes
 | 
						|
already_running="$(ps -fC 'grep' -N | grep 'low-battery.sh' | wc -l)"
 | 
						|
if [[ $already_running -gt 1 ]]; then
 | 
						|
	pkill -f --older 1 'low-battery.sh'
 | 
						|
fi
 | 
						|
 | 
						|
while [[ 0 -eq 0 ]]; do
 | 
						|
	battery_status="$(cat /sys/class/power_supply/BAT1/status)"
 | 
						|
	battery_charge="$(cat /sys/class/power_supply/BAT1/capacity)"
 | 
						|
 | 
						|
	if [[ $battery_status == 'Discharging' && $battery_charge -le 25 ]]; then
 | 
						|
		if   [[ $battery_charge -le 5 ]]; then
 | 
						|
			notify-send --icon="${XDG_CONFIG_HOME:-~/.config}/dunst/images/Low-Battery.png" --urgency=critical "Battery critical!" "${battery_charge}%"
 | 
						|
			sleep 180
 | 
						|
		elif [[ $battery_charge -le 10 ]]; then
 | 
						|
			notify-send --icon="${XDG_CONFIG_HOME:-~/.config}/dunst/images/Low-Battery2.png" --urgency=critical "Battery critical!" "${battery_charge}%"
 | 
						|
			sleep 600
 | 
						|
		elif [[ $battery_charge -le 15 ]]; then
 | 
						|
			notify-send --icon="${XDG_CONFIG_HOME:-~/.config}/dunst/images/Low-Battery2.png" "Battery low!" "${battery_charge}%"
 | 
						|
			sleep 600
 | 
						|
		elif [[ $battery_charge -le 20 ]]; then
 | 
						|
			notify-send --icon="${XDG_CONFIG_HOME:-~/.config}/dunst/images/Low-Battery2.png" "Battery low!" "${battery_charge}%"
 | 
						|
			sleep 600
 | 
						|
		else
 | 
						|
			sleep 600
 | 
						|
		fi
 | 
						|
	else
 | 
						|
		sleep 1200
 | 
						|
	fi
 | 
						|
done
 |