#!/bin/sh
# Fetch current mic levels
# (in current default Capture)

# Get volume levels
vol=$(amixer | grep "Capture" | grep -o '[0-9]*[0-9]%' | tail -n 1)
vol="${vol%\%*}" # Remove percentage sign

# If device is off (muted), notify mute, print volume otherwise
if amixer scontents | grep "Capture" | grep -q "\[off\]"; then
    echo " ──────────"
    notify-send -u low --replace-id=11 " Silenced" 2>/dev/null
    exit
fi

# Define bar progress with volume
case 1 in
    $((vol >= 100)) ) bar="━━━━━━━━━━" ;;
    $((vol >= 90))  ) bar="━━━━━━━━━─" ;;
    $((vol >= 80))  ) bar="━━━━━━━━──" ;;
    $((vol >= 70))  ) bar="━━━━━━━───" ;;
    $((vol >= 60))  ) bar="━━━━━━────" ;;
    $((vol >= 50))  ) bar="━━━━━─────" ;;
    $((vol >= 40))  ) bar="━━━━──────" ;;
    $((vol >= 30))  ) bar="━━━───────" ;;
    $((vol >= 20))  ) bar="━━────────" ;;
    $((vol >= 10))  ) bar="━─────────" ;;
    $((vol >= 0))   ) bar="──────────" ;;
esac

# Print and notify
echo " $bar"
notify-send -u low --replace-id=11 " $bar" 2>/dev/null