aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaroline Larimore <caroline@larimo.re>2025-04-19 11:55:50 -0700
committerCaroline Larimore <caroline@larimo.re>2025-04-19 11:55:50 -0700
commit355afe36ea6b70bdec74d2cdc73fd856f2389381 (patch)
tree9b3876145c68be19bcf453bfc327f0afb8150b88
parentb83172582880e0880f225b0e77969ca8c7f8bcc8 (diff)
home: mute script
-rw-r--r--modules/home/suites/desktop/default.nix4
-rw-r--r--modules/home/tools/default.nix3
-rw-r--r--packages/mute/default.nix39
3 files changed, 46 insertions, 0 deletions
diff --git a/modules/home/suites/desktop/default.nix b/modules/home/suites/desktop/default.nix
index 530a63a..985dca2 100644
--- a/modules/home/suites/desktop/default.nix
+++ b/modules/home/suites/desktop/default.nix
@@ -16,6 +16,10 @@ in {
firefox.enable = true;
};
+ tools = {
+ mute.enable = true;
+ };
+
desktop.components = {
i3.enable = true;
diff --git a/modules/home/tools/default.nix b/modules/home/tools/default.nix
index 9627d0f..98b37c7 100644
--- a/modules/home/tools/default.nix
+++ b/modules/home/tools/default.nix
@@ -11,5 +11,8 @@ with lib; with lib.${namespace}; {
];
persist = [ ".wine" ];
})
+ (mkSimpleTool "mute" {
+ packages = [ cxl.mute ];
+ })
];
}
diff --git a/packages/mute/default.nix b/packages/mute/default.nix
new file mode 100644
index 0000000..b868acd
--- /dev/null
+++ b/packages/mute/default.nix
@@ -0,0 +1,39 @@
+{ lib, pkgs, ... }:
+
+let
+ pactl = "${pkgs.pulseaudio}/bin/pactl";
+ jq = "${pkgs.jq}/bin/jq";
+in pkgs.writeShellScriptBin "mute" ''
+ set -euo pipefail
+ IFS=$'\n\t'
+
+ target="''${1:-0}"
+ inputs="$(${pactl} -f json list sink-inputs)"
+
+ if [[ "''${1:-}" != "" ]]; then
+ index="$(${jq} '.['$target'].index' <<< "$inputs")"
+ muted="$(${jq} '.['$target'].mute' <<< "$inputs")"
+ if [[ "$muted" = "true" ]]; then
+ ${pactl} set-sink-input-mute "$index" false
+ else
+ ${pactl} set-sink-input-mute "$index" true
+ fi
+
+ inputs="$(${pactl} -f json list sink-inputs)"
+ fi
+
+ count="$(${jq} 'length' <<< "$inputs")"
+ for ((i = 0; i < $count; i++)); do
+ index="$(${jq} '.['$i'].index' <<< "$inputs")"
+ muted="$(${jq} '.['$i'].mute' <<< "$inputs")"
+ name="$(${jq} '.['$i'].properties."application.name"' <<< "$inputs")"
+ media="$(${jq} '.['$i'].properties."media.name"' <<< "$inputs")"
+
+ state=" "
+ if [[ "$muted" = "true" ]]; then
+ state="*"
+ fi
+
+ printf ' [%d] %s %d\t%s\t(%s)\n' "$i" "$state" "$index" "$name" "$media"
+ done
+''