this post was submitted on 17 Jun 2024
18 points (100.0% liked)

Linux

48099 readers
807 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 5 years ago
MODERATORS
 

I use the following oneliner to switch sinks:

wpctl set-default $(pw-cli i $(pactl list short sinks | awk '{print $2}' | sd 'easyeffects_sink\n' '' | sd "$(pactl get-default-sink)\n" '' | rg '.' || echo "$(pactl get-default-sink)" | tofi --prompt-text " " --height 40% --width 40% --auto-accept-single true ) | rg -oP 'id: \K\w+') && notify-send --urgency=low --icon=/usr/share/icons/Flat-Remix-Red-Dark/panel/audio-volume-high-symbolic.svg "$(pactl list sinks | rg -A 1 "Name: $(pactl get-default-sink)" | rg Description: | sd ' Description: ' '')" -h string:x-canonical-private-synchronous:sink-state && pw-play --volume=0.2 /usr/share/sounds/freedesktop/stereo/audio-volume-change.oga &!

This is great, however, i'd like it if the sink menu showed the descriptions for selection instead of the actual sink names

I've started a script like the following:

RET=$(pactl list sinks | rg Description: | sd '	Description: ' '') | tofi
case $RET in
	pactl list sinks | rg Description: | sd '	Description: ' '') pactl list short sinks | awk '{print $2}'
esac

but that doesn't seem to work at all, any ideas for how to get this working?

edit: I found a better solution

$sinkswitch = wpctl set-default $(pw-cli i $(pactl list sinks | rg --fixed-strings -B 1 "$(pactl list sinks | rg Description: | sd ' Description: ' '' | sd 'Easy Effects Sink' '' | sd --fixed-strings "$(pactl list sinks | rg -A 1 "Name: $(pactl get-default-sink)" | rg Description: | sd ' Description: ' '')" '' | rg '.' || echo "$(pactl list sinks | rg -A 1 "Name: $(pactl get-default-sink)" | rg Description: | sd ' Description: ' '')" | tofi --prompt-text " " --height 40% --width 40% --auto-accept-single true )" | rg Name: | awk '{print $2}' ) | rg -oP 'id: \K\w+') && notify-send --urgency=low --icon=/usr/share/icons/Flat-Remix-Red-Dark/panel/audio-volume-high-symbolic.svg "$(pactl list sinks | rg -A 1 "Name: $(pactl get-default-sink)" | rg Description: | sd ' Description: ' '')" -h string:x-canonical-private-synchronous:sink-state && pw-play --volume=0.2 /usr/share/sounds/freedesktop/stereo/audio-volume-change.oga &!

top 2 comments
sorted by: hot top controversial new old
[–] gnuhaut@lemmy.ml 2 points 4 months ago (1 children)

Like this?

#!/bin/sh
set -eu

name_from_desc() {
    LANG=C pactl list sinks \
        | awk 'BEGIN {FS=": "} /Name:/ {name=$2} /Description:/ {print name, ":", $2}' \
        | while IFS=' : ' read name desc; do
        if [ "$desc" = "$1" ]; then echo "$name"; fi
    done
}

id_from_name() {
    pw-cli i "$1" | awk '/id:/ {print $2}'
}

ret=$(LANG=C pactl list sinks | awk 'BEGIN {FS=": "} /Description:/ {print $2}' | tofi)

wpctl set-default $(id_from_name $(name_from_desc "$ret"))

I don't get how that case statement of yours is even supposed to work. I'm pretty sure that's just a syntax error. I guess you want to map from description to name? But that's not remotely what that does.

[–] Communist@lemmy.ml 2 points 4 months ago* (last edited 4 months ago)

I made a better solution in my post that works perfectly... and is better for me because it isn't a script (I don't like adding additional dotfiles) sorry for the unnecessary effort.