dotfiles/status.sh
2024-12-19 21:44:36 +01:00

41 lines
1.3 KiB
Bash

# The Sway configuration file in ~/.config/sway/config calls this script.
# You should see changes to the status bar after saving this script.
# If not, do "killall swaybar" and $mod+Shift+c to reload the configuration.
# The abbreviated weekday (e.g., "Sat"), followed by the ISO-formatted date
# like 2018-10-06 and the time (e.g., 14:01)
date_formatted=$(date "+%a %d-%m-%+4Y %H:%M")
# Returns the battery status: "Full", "Discharging", or "Charging".
battery_status=$(cat /sys/class/power_supply/BAT1/status)
battery_level=$(cat /sys/class/power_supply/BAT1/capacity)
battery_symbol=🔋
if [ "$battery_level" -lt 20 ]; then
battery_symbol=🪫
fi
# Get volume left side Master
volume_left_side=$(amixer sget Master | grep "Front Left:" | awk '{print $5}' | sed 's/[][]//g' | sed 's/%//g')
# Muted
muted=$(amixer sget Master | grep "Front Left:" | awk '{print $6}' | sed 's/[][]//g')
volume_symbol=🔈
# Check Muted
if [ "$muted" = "off" ]; then
volume_symbol=🔇
else
# Volume symbol compared to volume level
if [ "$volume_left_side" -ge 60 ]; then
volume_symbol=🔊
elif [ "$volume_left_side" -ge 20 ]; then
volume_symbol=🔉
elif [ "$volume_left_side" -ge 0 ]; then
volume_symbol=🔈
fi
fi
# Final Echo
echo "$volume_left_side%" $volume_symbol '|' "$battery_level%" $battery_symbol $battery_status '|' $date_formatted