|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
while [ $# -gt 0 ] ; do
|
|
|
|
|
case "$1" in
|
|
|
|
|
"--newline")
|
|
|
|
|
newline=1
|
|
|
|
|
;;
|
|
|
|
|
"--unit")
|
|
|
|
|
unitsymbol="%"
|
|
|
|
|
;;
|
|
|
|
|
"--no-value")
|
|
|
|
|
no_value=1
|
|
|
|
|
;;
|
|
|
|
|
"--socket")
|
|
|
|
|
_pipe_dir="${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime}/acejuice"
|
|
|
|
|
mkdir -p "$_pipe_dir"
|
|
|
|
|
NPIPE_OUT="$_pipe_dir/main.sock"
|
|
|
|
|
unset _pipe_dir
|
|
|
|
|
if ! mkfifo "$NPIPE_OUT" 2> /dev/null; then
|
|
|
|
|
printf "fifo '%s' already present\n" "$NPIPE_OUT" >&2
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
"--icon")
|
|
|
|
|
case $2 in
|
|
|
|
|
"ascii"|""|"--"*)
|
|
|
|
|
case "$2" in
|
|
|
|
|
"--"*|"")
|
|
|
|
|
: # skip if it's a parameter or is empty
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
iconize=1
|
|
|
|
|
iconlvl0="[----]"
|
|
|
|
|
iconlvl1="[#---]"
|
|
|
|
|
iconlvl2="[##--]"
|
|
|
|
|
iconlvl3="[###-]"
|
|
|
|
|
iconlvl4="[####]"
|
|
|
|
|
iconmute="[mute]"
|
|
|
|
|
;;
|
|
|
|
|
"nerd")
|
|
|
|
|
shift
|
|
|
|
|
iconize=1
|
|
|
|
|
icon_nerd=1
|
|
|
|
|
iconlvl0=
|
|
|
|
|
iconlvl1=
|
|
|
|
|
iconlvl2=
|
|
|
|
|
iconlvl3=
|
|
|
|
|
iconmute=
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
printf "Icon coding not supported. Aborting...\n"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
|
|
|
|
"--icon-mute")
|
|
|
|
|
iconize_mute=1
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
printf "Parameter not recognized. Aborting...\n"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
DEFAULT_SINK_NAME=""
|
|
|
|
|
DEFAULT_SOURCE_NAME=""
|
|
|
|
|
|
|
|
|
|
lvl=""
|
|
|
|
|
|
|
|
|
|
__lvlbar(){
|
|
|
|
|
if [ "$iconize_mute" = 1 ] && [ "$2" = "muted" ]; then
|
|
|
|
|
icon="$iconmute"
|
|
|
|
|
else
|
|
|
|
|
if [ "$icon_nerd" = 1 ]; then
|
|
|
|
|
if [ "$1" -le 0 ]; then
|
|
|
|
|
icon="${iconlvl0}"
|
|
|
|
|
elif [ "$1" -le 30 ]; then
|
|
|
|
|
icon="${iconlvl1}"
|
|
|
|
|
elif [ "$1" -le 85 ]; then
|
|
|
|
|
icon="${iconlvl2}"
|
|
|
|
|
elif [ "$1" -le 100 ]; then
|
|
|
|
|
icon="${iconlvl3}"
|
|
|
|
|
else
|
|
|
|
|
icon="${iconlvl4}"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
if [ "$1" -le 5 ]; then
|
|
|
|
|
icon="${iconlvl0}"
|
|
|
|
|
elif [ "$1" -le 15 ]; then
|
|
|
|
|
icon="${iconlvl0}"
|
|
|
|
|
elif [ "$1" -le 35 ]; then
|
|
|
|
|
icon="${iconlvl1}"
|
|
|
|
|
elif [ "$1" -le 65 ]; then
|
|
|
|
|
icon="${iconlvl2}"
|
|
|
|
|
elif [ "$1" -le 97 ]; then
|
|
|
|
|
icon="${iconlvl3}"
|
|
|
|
|
else
|
|
|
|
|
icon="${iconlvl4}"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__send(){
|
|
|
|
|
case $1 in
|
|
|
|
|
DEFAULT_SINK_NAME)
|
|
|
|
|
DEFAULT_SINK_NAME="$2"
|
|
|
|
|
;;
|
|
|
|
|
DEFAULT_SOURCE_NAME)
|
|
|
|
|
DEFAULT_SOURCE_NAME="$2"
|
|
|
|
|
;;
|
|
|
|
|
SINKVOL)
|
|
|
|
|
[ "$no_value" = 1 ] && : || lvl=$3
|
|
|
|
|
[ "$iconize" = 1 ] && __lvlbar "$3" "$2" || :
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
:
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
if [ -n "$NPIPE_OUT" ]; then
|
|
|
|
|
printf ":SET audi %b%s%s%s%s%b%s" "${color}" "${icon}" "${status}" "${lvl}" "${unitsymbol}" "${colend}${colbgend}" "${sep}" > "$NPIPE_OUT"
|
|
|
|
|
else
|
|
|
|
|
printf ":SET audi %b%s%s%s%s%b%s" "${color}" "${icon}" "${status}" "${lvl}" "${unitsymbol}" "${colend}${colbgend}" "${sep}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "$newline" = 1 ]; then
|
|
|
|
|
if [ -n "$NPIPE_OUT" ]; then
|
|
|
|
|
printf "\n" > "$NPIPE_OUT"
|
|
|
|
|
else
|
|
|
|
|
printf "\n"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [ -t 0 ]; then
|
|
|
|
|
_pipe_dir="${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime}/acejuice"
|
|
|
|
|
mkdir -p "$_pipe_dir"
|
|
|
|
|
NPIPE_IN="$_pipe_dir/acejuice-pulse.sock"
|
|
|
|
|
unset _pipe_dir
|
|
|
|
|
|
|
|
|
|
if ! mkfifo "$NPIPE_IN" 2> /dev/null; then
|
|
|
|
|
printf "fifo '%s' already present\n" "$NPIPE_IN" >&2
|
|
|
|
|
fi
|
|
|
|
|
while read -r line ; do
|
|
|
|
|
__send $line
|
|
|
|
|
done < "$NPIPE_IN"
|
|
|
|
|
else
|
|
|
|
|
while read -r line ; do
|
|
|
|
|
__send $line
|
|
|
|
|
done
|
|
|
|
|
fi
|