Files
opalfiles/.config/sway/scripts/bar.sh
2024-09-28 10:54:24 -07:00

104 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
get_date() {
echo -n "$(date '+%a %d/%m/%y %H:%M')"
}
get_battery() {
BATTERY_PATH="/sys/class/power_supply/BAT0"
if [ -f "$BATTERY_PATH/capacity" ]; then
BAT_PERCENT=$(cat "$BATTERY_PATH/capacity")
BAT_STATUS=$(cat "$BATTERY_PATH/status")
# Determine battery icon based on percentage
case $BAT_PERCENT in
9[5-9]|100)
ICON="󰁹" # Full battery (95%-100%)
;;
9[0-4])
ICON="󰂂" # 90%-94% battery
;;
8[0-9])
ICON="󰂁" # 80% battery
;;
7[0-9])
ICON="󰂀" # 70% battery
;;
6[0-9])
ICON="󰁿" # 60% battery
;;
5[0-9])
ICON="󰁾" # 50% battery
;;
4[0-9])
ICON="󰁽" # 40% battery
;;
3[0-9])
ICON="󰁼" # 30% battery
;;
2[0-9])
ICON="󰁻" # 20% battery
;;
1[0-9])
ICON="󰂃" # 10% battery
;;
*)
ICON="󰂃" # Critical battery (less than 10%)
;;
esac
# Display charging icon if the battery is charging
if [ "$BAT_STATUS" == "Charging" ] || [ "$BAT_STATUS" == "Unknown" ]; then
echo -n "󱐋 $BAT_PERCENT%"
else
echo -n "$ICON $BAT_PERCENT%"
fi
# Send notifications at critical levels
case $BAT_PERCENT in
30)
notify-send -u normal "Battery at 30%" "Consider plugging in."
;;
20)
notify-send -u normal "Battery at 20%" "Battery is getting low."
;;
10)
notify-send -u critical "Battery at 10%" "Battery is critically low!"
;;
[0-5])
notify-send -u critical "Battery at 5%" "Battery is about to die!"
;;
esac
else
echo -n "Battery not found"
fi
}
get_volume() {
# Get the default sink (output device)
SINK=$(pactl info | awk -F': ' '/Default Sink/ {print $2}')
# Get the volume percentage
VOLUME=$(pactl get-sink-volume "$SINK" | awk '{print $5}' | head -n1)
# Get the mute status
MUTE_STATUS=$(pactl get-sink-mute "$SINK" | awk '{print $2}')
# Check if the output is muted
if [ "$MUTE_STATUS" == "no" ]; then
# Volume is not muted, display the volume percentage
echo -n "$VOLUME"
else
# Volume is muted, display mute icon
echo -n " Muted"
fi
}
while true; do
echo "$(get_volume) $(get_date) $(get_battery)"
sleep 1
done