Files
i3wm-ubuntu-dotfiles/.config/polybar/scripts/volume.sh
T
2026-01-29 23:19:44 +05:30

38 lines
791 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Suppress locale-related float warnings
LC_NUMERIC=C
# Get default sink volume info safely
VOL_LINE=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ 2>/dev/null)
if [ -z "$VOL_LINE" ]; then
echo "🔇 No Sink"
exit 0
fi
# Extract volume (0.001.50 range) and convert to integer percent
VOL=$(echo "$VOL_LINE" | awk '{printf "%d", $2 * 100}')
# Check mute status
MUTE=$(echo "$VOL_LINE" | grep -q "MUTED" && echo yes || echo no)
# Sanitize volume
if [ -z "$VOL" ]; then VOL=0; fi
if [ "$VOL" -gt 150 ]; then VOL=150; fi
if [ "$MUTE" = "yes" ]; then VOL=0; fi
# Choose icon
if [ "$VOL" -eq 0 ]; then
EMOJI="🔇"
elif [ "$VOL" -le 30 ]; then
EMOJI="🔈"
elif [ "$VOL" -le 70 ]; then
EMOJI="🔉"
else
EMOJI="🔊"
fi
# Output
echo "$EMOJI $VOL%"