Fix select-sound-output.sh
This commit is contained in:
@@ -12,7 +12,13 @@ get_default_sink() {
|
|||||||
pw-dump | jq -r --argjson def_sink "${match}" \
|
pw-dump | jq -r --argjson def_sink "${match}" \
|
||||||
'.[] | select(.id == $def_sink)
|
'.[] | select(.id == $def_sink)
|
||||||
| .info.props
|
| .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
|
else
|
||||||
echo "error: getting default sink with wpctl failed" >&2
|
echo "error: getting default sink with wpctl failed" >&2
|
||||||
exit 1
|
exit 1
|
||||||
@@ -22,9 +28,28 @@ get_default_sink() {
|
|||||||
local current_sink_desc="$(get_default_sink)"
|
local current_sink_desc="$(get_default_sink)"
|
||||||
|
|
||||||
local JQ_SCRIPT=$(<<'EOF'
|
local JQ_SCRIPT=$(<<'EOF'
|
||||||
.[] | select(.type == "PipeWire:Interface:Node"
|
. as $input
|
||||||
|
| .[]
|
||||||
|
| select(.type == "PipeWire:Interface:Node"
|
||||||
and .info.props.["media.class"] == "Audio/Sink")
|
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
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,15 +63,17 @@ fi
|
|||||||
|
|
||||||
generate_icon_names() {
|
generate_icon_names() {
|
||||||
# I got this idea from the pavucontrol source
|
# I got this idea from the pavucontrol source
|
||||||
# - First try the icon name as is
|
# 1. First try the icon name as is
|
||||||
# - Then concatenate "-symbolic"
|
# 2. Then concatenate "-symbolic"
|
||||||
# - Then remove the last dash (-) character and everything after it
|
# 3. Then remove the last dash (-) character and everything after it
|
||||||
# - Then again try that with "-symbolic"
|
# 4. Then again try that with "-symbolic"
|
||||||
|
# 5. Repeat 3 and 4 while there is a dash (-) in the name
|
||||||
local nonl="${1//%'\n'/}"
|
local nonl="${1//%'\n'/}"
|
||||||
printf '%s,%s' "${nonl}" "${nonl}-symbolic"
|
printf '%s,%s' "${nonl}" "${nonl}-symbolic"
|
||||||
if [[ ${1} = *-* ]]; then
|
while [[ ${nonl} = *-* ]]; do
|
||||||
printf ',%s,%s' "${nonl%-*}" "${nonl%-*}-symbolic"
|
printf ',%s,%s' "${nonl%-*}" "${nonl%-*}-symbolic"
|
||||||
fi
|
nonl="${nonl%-*}"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
local -a ids descs fuzzel_ents
|
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
|
for id desc icon in ${id_desc_pairs}; do
|
||||||
ids+=("${id}")
|
ids+=("${id}")
|
||||||
descs+=("${desc}")
|
descs+=("${desc}")
|
||||||
|
generate_icon_names "${icon}"
|
||||||
|
echo
|
||||||
fuzzel_ents+=("${desc//$'\n'/}" "$(generate_icon_names "${icon}")")
|
fuzzel_ents+=("${desc//$'\n'/}" "$(generate_icon_names "${icon}")")
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user