#!/bin/sh

# This script display an appropriate volume icon according to the volume level

# Authors: Piotr Miller, @natemaia
# e-mail: nwg.piotr@gmail.com
# Website: http://nwg.pl
# Project: https://github.com/nwg-piotr/tint2-executors
# License: GPL3

# Dependencies: `alsa-utils`

if [[ "$(amixer sget Master | awk -F'[][]' '/Right:|Mono:/ && NF > 1 {print $4}')" = "on" ]]; then

    # search for the lines containing 'Right:' or 'Mono:', when more than 1 field exists
    # we strip the trailing '%' and round it up with printf "%0.0f" just in case
    vol=$(amixer sget Master | awk -F'[][]' '/Right:|Mono:/ && NF > 1 {sub(/%/, ""); printf "%0.0f\n", $2}')

    if [[ ${vol} -ge 90 ]]; then
        echo /usr/share/icons/papirus-antix/24x24/panel/audio-volume-high.png
    elif [[ ${vol} -ge 40 ]]; then
        echo /usr/share/icons/papirus-antix/24x24/panel/audio-volume-medium.png
    elif [[ ${vol} -ge 10 ]]; then
        echo /usr/share/icons/papirus-antix/24x24/panel/audio-volume-low.png
    else
        echo /usr/share/icons/papirus-antix/24x24/panel/audio-volume-muted.png
    fi
    if  [[ $1 = "-l" ]]; then
        echo ${vol}%
    fi
else
    echo echo /usr/share/icons/papirus-antix/24x24/panel/audio-volume-muted.png
fi
