#!/usr/bin/bash

set -e






# https://blog.dhampir.no/content/sleeping-without-a-subprocess-in-bash-and-how-to-sleep-forever
snore() {
    local IFS
    [[ -n "${_snore_fd:-}" ]] || exec {_snore_fd}<> <(:)
    read -r ${1:+-t "$1"} -u $_snore_fd || :
}

getter() {

  DELAY=0.2

  while snore $DELAY; do

    SINKS=$(pactl --format=json list sinks)
    CURRENT_SINK=$(pactl get-default-sink)

    CURRENT_SINK_OBJ=$(pactl --format=json list sinks | jq '.[] | select(.state="$(pactl get-default-sink)")')

    echo $CURRENT_SINK_OBJ
    exit 1

s="text|alt|tooltip|class
$CPU_GOV_SHORT|$CPU_GOV_FULL|CPU Mode: $CPU_GOV_FULL|cpugov"

jq --unbuffered --compact-output -Rn '
( input  | split("|") ) as $keys |
( inputs | split("|") ) as $vals |
[[$keys, $vals] | transpose[] | {key:.[0],value:.[1]}] | from_entries
' <<<"$s"

  done
}





if [[ $1 = "-g" ]] then
  getter
fi


exit 0
#echo '{"text": "$(CPU_GOV)", "alt": "$CPU_GOV", "tooltip": "$CPU_GOV", "class": "$cpugov" }'