summaryrefslogtreecommitdiff
path: root/common/modules/mango/scripts.nix
diff options
context:
space:
mode:
Diffstat (limited to 'common/modules/mango/scripts.nix')
-rw-r--r--common/modules/mango/scripts.nix77
1 files changed, 77 insertions, 0 deletions
diff --git a/common/modules/mango/scripts.nix b/common/modules/mango/scripts.nix
new file mode 100644
index 0000000..b3de75d
--- /dev/null
+++ b/common/modules/mango/scripts.nix
@@ -0,0 +1,77 @@
+{ pkgs, ... }:
+let
+ # CHANGED: writeShellScript -> writeShellScriptBin
+ volume-control = pkgs.writeShellScriptBin "volume-control" ''
+ TAG="audio-volume"
+
+ function get_vol {
+ ${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print int($2 * 100)}'
+ }
+
+ case $1 in
+ up) ${pkgs.wireplumber}/bin/wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+ ;;
+ down) ${pkgs.wireplumber}/bin/wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- ;;
+ mute) ${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle ;;
+ esac
+
+ vol=$(get_vol)
+ is_muted=$(${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep "MUTED")
+
+ if [ -n "$is_muted" ]; then
+ ${pkgs.dunst}/bin/dunstify -a "Volume" -u low \
+ -h string:x-canonical-private-synchronous:$TAG \
+ "Volume: Muted"
+ else
+ ${pkgs.dunst}/bin/dunstify -a "Volume" -u low \
+ -h string:x-canonical-private-synchronous:$TAG \
+ -h int:value:"$vol" \
+ "Volume: $vol%"
+ fi
+ '';
+
+ # CHANGED: writeShellScript -> writeShellScriptBin
+ brightness-control = pkgs.writeShellScriptBin "brightness-control" ''
+ TAG="screen-brightness"
+
+ case $1 in
+ up) ${pkgs.brightnessctl}/bin/brightnessctl set +5% ;;
+ down) ${pkgs.brightnessctl}/bin/brightnessctl set 5%- ;;
+ esac
+
+ # Get current percentage
+ current=$(${pkgs.brightnessctl}/bin/brightnessctl info | grep -oP '\(\K[0-9]+(?=%\))')
+
+ ${pkgs.dunst}/bin/dunstify -a "Brightness" -u low \
+ -h string:x-canonical-private-synchronous:$TAG \
+ -h int:value:"$current" \
+ "Brightness: $current%"
+ '';
+
+ # CHANGED: writeShellScript -> writeShellScriptBin
+ mic-control = pkgs.writeShellScriptBin "mic-control" ''
+ TAG="audio-mic"
+
+ case $1 in
+ toggle) ${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle ;;
+ esac
+
+ is_muted=$(${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | grep "MUTED")
+
+ if [ -n "$is_muted" ]; then
+ ${pkgs.dunst}/bin/dunstify -a "Microphone" -u low \
+ -h string:x-canonical-private-synchronous:$TAG \
+ "Microphone: Muted"
+ else
+ ${pkgs.dunst}/bin/dunstify -a "Microphone" -u low \
+ -h string:x-canonical-private-synchronous:$TAG \
+ "Microphone: On"
+ fi
+ '';
+in
+{
+ home.packages = [
+ volume-control
+ brightness-control
+ mic-control
+ ];
+}