#!/bin/sh # volume module for status/stellar # load config module_config [ -e "$HOME/.config/speedwm/statusrc" ] && . $HOME/.config/speedwm/statusrc [ "$ENABLE_ITEM4" != "true" ] && exit [ -e "/tmp/module_vol_hidden" ] && exit command -v pactl > /dev/null && BACKEND=pactl || BACKEND=amixer command -v awk > /dev/null || exit # click CLICK() { command -v speedwm-audioctrl > /dev/null || return # values VOL_VOLUME="$(speedwm-audioctrl -getvol)" VOL_ISPULSE="$(speedwm-audioctrl -getbackend)" GETDATA [ -e "/tmp/speedwm-button" ] && BUTTON="$(cat /tmp/speedwm-button)" || BUTTON="0" [ -z "$TERMINAL" ] && TERMINAL=st [ -n "$ICON" ] && ICONSPACING=" " # one character spacing # check value of button case "$BUTTON" in "3") $TERMINAL speedwm-audioctrl -runmixer ; exit ;; esac # send the notification SEND_NOTIF() { FULL_VOL="${ICON}${ICONSPACING}$VOL_VOLUME" notify-send "$FULL_VOL" # some information echo "Notification sent successfully!" echo "INFO: $FULL_VOL" return } command -v notify-send > /dev/null && SEND_NOTIF || echo "FATAL: libnotify not installed, can't send notification." return } # get data GETDATA() { [ "$BACKEND" = "pactl" ] && VOL="$(pactl get-sink-volume @DEFAULT_SINK@ | awk '{ print $5; exit }' | sed "s/\%//g")" || VOL="$(amixer -c 0 get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/")" [ "$VOL" -gt "99" ] && ICON="$ITEM4_ICON_100 " [ "$VOL" -lt "100" ] && ICON="$ITEM4_ICON_75" [ "$VOL" -lt "51" ] && ICON="$ITEM4_ICON_50" [ "$VOL" -lt "26" ] && ICON="$ITEM4_ICON_25" [ "$VOL" -lt "1" ] && ICON="$ITEM4_ICON_0" # mute status [ "$BACKEND" = "pactl" ] && pactl get-sink-mute @DEFAULT_SINK@ | grep -q yes && ICON="$ITEM4_ICON_MUTED" && MUTEDATA=" $ITEM4_MUTE_TEXT" || MUTEDATA="" [ "$ITEM4_SHOW_MUTE" != "true" ] && MUTEDATA="" } # information itself PRINT() { GETDATA VOL="${VOL}%" echo "$ITEM4_SEPARATOR $ICON $VOL$MUTEDATA" } # argument 1 case "$1" in "") CLICK ;; "--print-file") PRINT > /tmp/module_vol ;; "--print") PRINT ;; "--click") CLICK ;; esac