switch audio with rofi and add extraLib

This commit is contained in:
Noah Masur
2023-03-22 21:15:41 -04:00
parent 9b97c9ac84
commit f69d233c39
7 changed files with 50 additions and 16 deletions

View File

@ -17,6 +17,10 @@
type = lib.types.str;
description = "Command to use for choosing windows";
};
audioSwitchCommand = lib.mkOption {
type = lib.types.str;
description = "Command to use for switching audio sink";
};
toggleBarCommand = lib.mkOption {
type = lib.types.str;
description = "Command to hide and show the status bar.";

View File

@ -112,6 +112,8 @@ in {
"exec --no-startup-id ${config.launcherCommand}";
"${modifier}+Shift+s" =
"exec --no-startup-id ${config.systemdSearch}";
"${modifier}+Shift+a" =
"exec --no-startup-id ${config.audioSwitchCommand}";
"Mod1+Tab" = "exec --no-startup-id ${config.altTabCommand}";
"${modifier}+Shift+c" = "reload";
"${modifier}+Shift+r" = "restart";

View File

@ -155,7 +155,16 @@
altTabCommand = "${
config.home-manager.users.${config.user}.programs.rofi.finalPackage
}/bin/rofi -show window -modi window";
audioSwitchCommand = "${
(pkgs.extraLib.mkScript {
name = "switch-audio";
file = ./rofi/pulse-sink.sh;
env = [
pkgs.ponymix
config.home-manager.users.${config.user}.programs.rofi.finalPackage
];
})
}/bin/switch-audio";
};
}

View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Credit: https://gist.github.com/Nervengift/844a597104631c36513c
sink=$(
ponymix -t sink list |
awk '/^sink/ {s=$1" "$2;getline;gsub(/^ +/,"",$0);print s" "$0}' |
rofi -dmenu -p 'pulseaudio sink:' -location 6 -width 100 |
grep -Po '[0-9]+(?=:)'
) &&
ponymix set-default -d "$sink" &&
for input in $(ponymix list -t sink-input | grep -Po '[0-9]+(?=:)'); do
echo "$input -> $sink"
ponymix -t sink-input -d "$input" move "$sink"
done