feat: Add statusbar and LARBS
This commit is contained in:
70
bin/statusbar/sb-battery
Executable file
70
bin/statusbar/sb-battery
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Prints out battery percentage
|
||||
|
||||
# Global config
|
||||
source config
|
||||
|
||||
# At which levels to trigger emoji at
|
||||
max=80
|
||||
high=70
|
||||
midhi=60
|
||||
mid=40
|
||||
low=20
|
||||
warn=20
|
||||
crit=5
|
||||
|
||||
# Emoji used by module
|
||||
i_charging=" "
|
||||
i_warning=" "
|
||||
i_full=" "
|
||||
i_high=" "
|
||||
i_midhi=" "
|
||||
i_mid=" "
|
||||
i_low=" "
|
||||
i_empty=" "
|
||||
|
||||
# status2d patch alternating background
|
||||
# background="^b#333333^"
|
||||
# background="^b#222222^"
|
||||
|
||||
# Read battery data
|
||||
bat_data="/sys/class/power_supply/BAT?*"
|
||||
|
||||
get_battery() {
|
||||
icon=""
|
||||
bat_icon=""
|
||||
|
||||
# The vast majority of people only use one battery.
|
||||
if [ ! -d $bat_data ]; then return; fi
|
||||
|
||||
# Get battery capacity and charging state
|
||||
capacity=$(cat $bat_data/capacity)
|
||||
charging=$(cat $bat_data/status)
|
||||
|
||||
# Add warning/charging symbols
|
||||
if [[ "$charging" == "Charging" ]]; then icon="$i_charging"
|
||||
elif [[ $capacity -le $warn ]]; then icon="$i_warning"
|
||||
fi
|
||||
|
||||
# Change battery symbol depending on capacity
|
||||
if [[ $capacity -ge $max ]]; then bat_icon=$i_full
|
||||
else
|
||||
case 1 in
|
||||
$(($capacity < $crit)) ) bat_icon=$i_empty ;;
|
||||
$(($capacity < $low)) ) bat_icon=$i_low ;;
|
||||
$(($capacity < $mid)) ) bat_icon=$i_mid ;;
|
||||
$(($capacity < $midhi)) ) bat_icon=$i_midhi ;;
|
||||
$(($capacity < $high)) ) bat_icon=$i_high ;;
|
||||
* ) bat_icon=$i_full ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Normalize capacity to a value between 0 and 100
|
||||
capacity=$(awk -v cap="$capacity" -v max="$max" \
|
||||
'BEGIN { printf "%.0f", cap * 100 / max }')
|
||||
|
||||
echo "$background$wb$icon$bat_icon $capacity%$we^d^"
|
||||
}
|
||||
|
||||
get_battery
|
||||
Reference in New Issue
Block a user