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

@ -121,6 +121,7 @@
inputs.nur.overlay
inputs.nix2vim.overlay
(import ./overlays/neovim-plugins.nix inputs)
(import ./overlays/lib.nix)
(import ./overlays/calibre-web.nix)
];

View File

@ -1,19 +1,6 @@
{ config, pkgs, lib, ... }:
let
# Quickly package shell scripts with their dependencies
# From https://discourse.nixos.org/t/how-to-create-a-script-with-dependencies/7970/6
mkScript = { name, file, env ? [ ] }:
pkgs.writeScriptBin name ''
for i in ${lib.concatStringsSep " " env}; do
export PATH="$i/bin:$PATH"
done
exec ${pkgs.bash}/bin/bash ${file} $@
'';
in {
{
home-manager.users.${config.user} = lib.mkIf pkgs.stdenv.isDarwin {
@ -32,7 +19,7 @@ in {
consul
noti # Create notifications programmatically
ipcalc # Make IP network calculations
(mkScript {
(pkgs.extraLib.mkScript {
name = "ocr";
file = ../../modules/common/shell/bash/scripts/ocr.sh;
env = [ tesseract ];

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

16
overlays/lib.nix Normal file
View File

@ -0,0 +1,16 @@
_final: prev: {
extraLib = prev.lib // {
# Quickly package shell scripts with their dependencies
# From https://discourse.nixos.org/t/how-to-create-a-script-with-dependencies/7970/6
mkScript = { name, file, env ? [ ] }:
prev.pkgs.writeScriptBin name ''
for i in ${prev.lib.concatStringsSep " " env}; do
export PATH="$i/bin:$PATH"
done
exec ${prev.pkgs.bash}/bin/bash ${file} $@
'';
};
}