this post was submitted on 02 Oct 2025
49 points (96.2% liked)

Linux

67605 readers
669 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 7 years ago
MODERATORS
 
$sinkswitch = bash -c 'set -euo pipefail; declare -A m=(); declare -a n=(); ex="^(easyeffects_sink|filter-chain|loopback|null-sink)([-_.].*)?$"; exec 3< <(pw-cli ls Node 2>/dev/null); exec 4< <(pw-metadata -n default 0 default.audio.sink 2>/dev/null); cur=; while IFS= read -r l <&4; do case $l in *"default.audio.sink"*) cur=${l##*\"name\":\"}; cur=${cur%%\"*}; break;; esac; done; id= desc= name= cls=; add(){ [[ $cls == "Audio/Sink" && -n $name ]] || return 0; [[ $name =~ $ex || $name == "$cur" ]] && return 0; local l=$desc; [[ -n ${m[$l]+x} ]] && l+=" [$id]"; m[$l]=$name; n+=("$l"); }; while IFS= read -r l <&3; do case $l in *"id "[0-9]*", type PipeWire:Interface:Node"*) add; id=${l##*id }; id=${id%%,*}; desc= name= cls=;; *"node.description = "*) desc=${l##* = \"}; desc=${desc%\"};; *"node.name = "*) name=${l##* = \"}; name=${name%\"};; *"media.class = "*) cls=${l##* = \"}; cls=${cls%\"};; esac; done; add; ((${##n[@]})) || exit 0; if ((${##n[@]}==1)); then c=${n[0]}; else c=$(printf "%s\n" "${n[@]}" | walker -d --minheight 1 -p "Audio output: " | head -n1 || true); fi; [[ -n $c ]] || exit 0; name=${m[$c]:-}; [[ -n $name ]] || exit 1; pw-metadata -n default 0 default.configured.audio.sink "{\"name\":\"$name\"}" Spa:String:JSON >/dev/null & s=/run/current-system/sw/share/sounds/freedesktop/stereo/audio-volume-change.oga; [[ -r $s ]] && pw-play --volume=0.2 "$s" >/dev/null 2>&1 & notify-send -u low -i /run/current-system/sw/share/icons/Flat-Remix-Red-Dark/panel/audio-volume-high-symbolic.svg "${c% \[*\]}" -h string:x-canonical-private-synchronous:sink-state >/dev/null 2>&1 &'


or, escaped for waybar:

"on-click-middle": "bash -c 'set -euo pipefail; declare -A m=(); declare -a n=(); ex=\"^(easyeffects_sink|filter-chain|loopback|null-sink)([-_.].*)?$\"; exec 3< <(pw-cli ls Node 2>/dev/null); exec 4< <(pw-metadata -n default 0 default.audio.sink 2>/dev/null); cur=; while IFS= read -r l <&4; do case $l in *\"default.audio.sink\"*) cur=${l##*\\\"name\\\":\\\"}; cur=${cur%%\\\"*}; break;; esac; done; id= desc= name= cls=; add(){ [[ $cls == \"Audio/Sink\" && -n $name ]] || return 0; [[ $name =~ $ex || $name == \"$cur\" ]] && return 0; local l=$desc; [[ -n ${m[$l]+x} ]] && l+=\" [$id]\"; m[$l]=$name; n+=(\"$l\"); }; while IFS= read -r l <&3; do case $l in *\"id \"[0-9]*\", type PipeWire:Interface:Node\"*) add; id=${l#*id }; id=${id%%,*}; desc= name= cls=;; *\"node.description = \"*) desc=${l#* = \\\"}; desc=${desc%\\\"};; *\"node.name = \"*) name=${l#* = \\\"}; name=${name%\\\"};; *\"media.class = \"*) cls=${l#* = \\\"}; cls=${cls%\\\"};; esac; done; add; ((${#n[@]})) || exit 0; if ((${#n[@]}==1)); then c=${n[0]}; else c=$(printf \"%s\\n\" \"${n[@]}\" | walker -d --minheight 1 -p \"Audio output: \" | head -n1 || true); fi; [[ -n $c ]] || exit 0; name=${m[$c]:-}; [[ -n $name ]] || exit 1; pw-metadata -n default 0 default.configured.audio.sink \"{\\\"name\\\":\\\"$name\\\"}\" Spa:String:JSON >/dev/null & s=/run/current-system/sw/share/sounds/freedesktop/stereo/audio-volume-change.oga; [[ -r $s ]] && pw-play --volume=0.2 \"$s\" >/dev/null 2>&1 & notify-send -u low -i /run/current-system/sw/share/icons/Flat-Remix-Red-Dark/panel/audio-volume-high-symbolic.svg \"${c% \\[*\\]}\" -h string:x-canonical-private-synchronous:sink-state >/dev/null 2>&1 &'",

there's probably a lot to improve here, took forever to get this working, did not do a cleanup pass, jfc this took forever, replace walker with your menu of choice, thought people should have this.

wishlist: change the icon based on volume level

edit: updated to a script that's basically a million times faster

old version:

real 0m0.050s user 0m0.043s sys 0m0.037s

new version:

real 0m0.021s user 0m0.013s sys 0m0.012s

you are viewing a single comment's thread
view the rest of the comments
[–] boredsquirrel@slrpnk.net 6 points 11 months ago (1 children)

Could you lint that please. This is unreadable XD

[–] communist@lemmy.frozeninferno.xyz 5 points 11 months ago

I worked hard to make it this unreadable