diff --git a/system-menu/select-sound-output.sh b/system-menu/select-sound-output.sh index 6d36065..1272dc1 100755 --- a/system-menu/select-sound-output.sh +++ b/system-menu/select-sound-output.sh @@ -12,7 +12,13 @@ get_default_sink() { pw-dump | jq -r --argjson def_sink "${match}" \ '.[] | select(.id == $def_sink) | .info.props - | "\(.["node.nick"]) - \(.["node.description"]) (\($def_sink))"' + | "\(if .["node.nick"] + then "\(.["node.nick"]) - " + else "" end)\(.["node.description"]) (\($def_sink))"' + if (( ${?} )); then + echo "error: pw-dump or jq failed with error code ${?}" >&2 + exit 1 + fi else echo "error: getting default sink with wpctl failed" >&2 exit 1 @@ -22,9 +28,28 @@ get_default_sink() { local current_sink_desc="$(get_default_sink)" local JQ_SCRIPT=$(<<'EOF' -.[] | select(.type == "PipeWire:Interface:Node" +. as $input + | .[] + | select(.type == "PipeWire:Interface:Node" and .info.props.["media.class"] == "Audio/Sink") - | "\(.id)\u0000\(.info.props.["node.nick"]) - \(.info.props.["node.description"]) (\(.id))\u0000\(.info.props.["device.icon-name"])\u0000" + | .id as $id + | .info.props + | if .["node.nick"] then + "\(.["node.nick"]) - " + else + "" + end as $nick_srt + | .["node.description"] as $desc + | if .["device.id"] then + .["device.id"] as $did + | $input.[] + | select(.id == $did) + | .info.props.["device.icon-name"] // "" + else + .["device.icon-name"] // "" + end as $icon + | debug($icon) + | "\($id)\u0000\($nick_srt)\($desc) (\($id))\u0000\($icon)\u0000" EOF ) @@ -38,15 +63,17 @@ fi generate_icon_names() { # I got this idea from the pavucontrol source - # - First try the icon name as is - # - Then concatenate "-symbolic" - # - Then remove the last dash (-) character and everything after it - # - Then again try that with "-symbolic" + # 1. First try the icon name as is + # 2. Then concatenate "-symbolic" + # 3. Then remove the last dash (-) character and everything after it + # 4. Then again try that with "-symbolic" + # 5. Repeat 3 and 4 while there is a dash (-) in the name local nonl="${1//%'\n'/}" printf '%s,%s' "${nonl}" "${nonl}-symbolic" - if [[ ${1} = *-* ]]; then + while [[ ${nonl} = *-* ]]; do printf ',%s,%s' "${nonl%-*}" "${nonl%-*}-symbolic" - fi + nonl="${nonl%-*}" + done } local -a ids descs fuzzel_ents @@ -54,6 +81,8 @@ local -a ids descs fuzzel_ents for id desc icon in ${id_desc_pairs}; do ids+=("${id}") descs+=("${desc}") + generate_icon_names "${icon}" + echo fuzzel_ents+=("${desc//$'\n'/}" "$(generate_icon_names "${icon}")") done