#!/bin/bash

source "$HOME/.config/rofi/scripts/_lib.sh"

setOption no-custom true
case $ROFI_RETV in
0)
  defaultSink=$(pactl get-default-sink)
  echo -en $(pactl --format=json list sinks | jq --arg default "$defaultSink" -r 'map("\(.name)\\0display\\x1f\(.description)\\x1fmeta\\x1fsinks,output,\(.description)\\x1ficon\\x1faudio-ready\\n") | add')

  defaultSource=$(pactl get-default-source)
  echo -en $(pactl --format=json list sources | jq --arg default "$defaultSource" -r 'map("\(.name)\\0display\\x1f\(.description)\\x1fmeta\\x1fsource,input,\(.description)\\x1ficon\\x1fmic-ready\\n") | add')
  ;;
1)
  name=$@
  pactl set-default-sink "$name"
  ;;
esac
