79 lines
1.8 KiB
Bash
Executable file
79 lines
1.8 KiB
Bash
Executable file
#!/bin/sh
|
|
# battery module for status/stellar
|
|
|
|
# load config
|
|
. $HOME/.config/speedwm/statusrc
|
|
BINDIR="$(dirname $(command -v speedwm_status))/"
|
|
|
|
# argument 1
|
|
ARG1="$1"
|
|
|
|
# clicking
|
|
CLICK() {
|
|
# values
|
|
ICON="$ITEM11_ICON"
|
|
BUTTON="$(cat /tmp/speedwm-button)"
|
|
BATTERY_FULL="$(acpi)"
|
|
|
|
command -v acpi > /dev/null || exit
|
|
|
|
case "$TERMINAL" in
|
|
"") TERMINAL=st
|
|
esac
|
|
|
|
# no spacing if there's no icon
|
|
if [ "$ICON" != "" ]; then
|
|
ICONSPACING=" " # one character spacing
|
|
fi
|
|
|
|
# send the notification
|
|
SEND_NOTIF() {
|
|
FULL_BATTERY="${ICON}${ICONSPACING}$BATTERY_FULL"
|
|
notify-send "$FULL_BATTERY"
|
|
|
|
echo "Notification sent successfully!"
|
|
echo "INFO: $FULL_BATTERY"
|
|
|
|
exit 0
|
|
}
|
|
|
|
command -v notify-send > /dev/null && SEND_NOTIF
|
|
echo "FATAL: libnotify not installed, can't send notification."
|
|
|
|
exit 1
|
|
}
|
|
|
|
# information itself
|
|
PRINT() {
|
|
if [ "$ENABLE_ITEM11" = "true" ]; then
|
|
# print capacity
|
|
if [ -e "/sys/class/power_supply/BAT0/capacity" ]; then
|
|
echo "$ITEM11_SEPARATOR $ITEM11_ICON $(cat /sys/class/power_supply/BAT0/capacity)%"
|
|
fi
|
|
|
|
# print capacity for second battery if it exists
|
|
if [ -e "/sys/class/power_supply/BAT1/capacity" ]; then
|
|
echo "$ITEM11_SEPARATOR $ITEM11_ICON $(cat /sys/class/power_supply/BAT1/capacity)%"
|
|
fi
|
|
|
|
# show charging status
|
|
if [ -e "${BINDIR}acpi" ]; then
|
|
if [ "$ITEM11_SHOW_CHARGING_STATUS" = "true" ]; then
|
|
CHARGESTATUS=$(echo ", $(acpi | awk '{ print $3 }' | sed "s|,||g" | sed "s|Discharging|$ITEM11_DISCHARGING_TEXT|g; s|Charging|$ITEM11_CHARGING_TEXT|g; s|Fully charged|$ITEM11_FULL_TEXT|g")") && echo $CHARGESTATUS
|
|
fi
|
|
fi
|
|
|
|
# append extra text
|
|
if [ "$ITEM11_APPEND" != "" ]; then
|
|
echo "$ITEM11_APPEND"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# argument 1
|
|
case "$ARG1" in
|
|
"") CLICK ;;
|
|
"--print") PRINT > /tmp/module_bat ;;
|
|
"--click") CLICK ;;
|
|
esac
|