#!/usr/bin/env fish

# Select the default audio source
set dump (string trim -c '"' (pw-dump | jq '.[] | select(.info.props."media.class" == "Audio/Source")' | jq '.id, .info.props."node.description"'))

set ids
set names

for i in (seq (count $dump))
    if test (math $i % 2) -eq 0
        set -a names $dump[$i]
    else
        set -a ids $dump[$i]
    end
end

set input (math (menu --index $names) + 1)

wpctl set-default $ids[$input]
