From 20cd92006eb0cffd5def2baf04ed2fc0a7861602 Mon Sep 17 00:00:00 2001 From: Myned Date: Fri, 27 Sep 2024 14:51:18 -0500 Subject: [PATCH] audio: refactor with argc Signed-off-by: Myned --- options/custom/desktops/hyprland/binds.nix | 2 +- options/custom/desktops/hyprland/settings.nix | 2 + options/custom/scripts/audio.sh | 71 +++++++++++++++++-- options/custom/scripts/default.nix | 2 + 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/options/custom/desktops/hyprland/binds.nix b/options/custom/desktops/hyprland/binds.nix index 6fe438b..0665cd9 100644 --- a/options/custom/desktops/hyprland/binds.nix +++ b/options/custom/desktops/hyprland/binds.nix @@ -180,7 +180,7 @@ in { (key "Up" "Super" "movewindow" "u") (key "Up" "Super+Shift" "movewindoworgroup" "u") - (key "0" "Super" "exec" "${audio}") + (key "0" "Super" "exec" "${audio} --bypass") (key "0" "Super+Shift" "exec" "${zoom}") (key "1" "Ctrl+Alt" "exec" "lifx state --brightness 0.01") (key "1" "Super" "workspace" "1") diff --git a/options/custom/desktops/hyprland/settings.nix b/options/custom/desktops/hyprland/settings.nix index 9a72f7f..2a8384e 100644 --- a/options/custom/desktops/hyprland/settings.nix +++ b/options/custom/desktops/hyprland/settings.nix @@ -6,6 +6,7 @@ }: with lib; let _1password = "${config.programs._1password-gui.package}/bin/1password"; + audio = config.home-manager.users.${config.custom.username}.home.file.".local/bin/audio".source; clipse = "${pkgs.clipse}/bin/clipse"; firefox-esr = "${ config.home-manager.users.${config.custom.username}.programs.firefox.finalPackage @@ -72,6 +73,7 @@ in { optionals config.custom.wallpaper ["wallpaper"] ++ [ sway-audio-idle-inhibit # Inhibit idle while audio is playing + "${audio} --init" # Enforce audio profile state "${clipse} --clear" # Clear clipboard history "${clipse} --listen" # Monitor clipboard "${_1password} --silent" # Launch password manager in background diff --git a/options/custom/scripts/audio.sh b/options/custom/scripts/audio.sh index 7599c89..6ce06f7 100644 --- a/options/custom/scripts/audio.sh +++ b/options/custom/scripts/audio.sh @@ -1,11 +1,68 @@ #! /usr/bin/env bash -if [[ -v 1 ]]; then - easyeffects --load-preset "$1" && - easyeffects --bypass 2 - notify-send '> audio' "$1" --urgency low +# @describe Wrapper for toggling between audio profiles +# +# https://github.com/sigoden/argc + +# HACK: Condition based on file content, requires execution at login to set state +#?? exec-once = audio --init + +# @meta combine-shorts +# @arg profile=Normalizer EasyEffects profile to toggle to +# @option -F --flat=`_default_flat` Flat profile to toggle from +# @option -f --file=`_default_file` Specify file for state +# @flag -b --bypass Toggle bypass instead of flat profile +# @flag -i --init Enforce state without toggling + +_default_file() { + echo "$HOME/.audio" +} + +_default_flat() { + echo Flat +} + +eval "$(argc --argc-eval "$0" "$@")" + +# Get current profile from file +if [[ -f "${argc_file:-}" ]]; then + profile="$(cat "${argc_file:-}")" else - easyeffects --load-preset Flat && - easyeffects --bypass 1 - notify-send '> audio' 'Bypass' --urgency low + # Create file with flat profile if missing + profile="${argc_flat:-}" + echo "$profile" > "${argc_file:-}" fi + +# Toggle profile +if ! [[ "${argc_init:-}" ]]; then + if [[ "$profile" == "${argc_profile:-}" ]]; then + # Flat or bypass + if [[ "${argc_bypass:-}" ]]; then + profile=1 + else + profile="${argc_flat:-}" + fi + else + # Specified profile + profile="${argc_profile:-}" + fi +fi + +# Enforce profile +if [[ "$profile" == 1 ]]; then + easyeffects --bypass 1 # Enable + + if ! [[ "${argc_init:-}" ]]; then + notify-send "> audio" "Bypass" --urgency low + fi +else + easyeffects --load-preset "$profile" + easyeffects --bypass 2 # Disable + + if ! [[ "${argc_init:-}" ]]; then + notify-send "> audio" "$profile" --urgency low + fi +fi + +# Save state +echo "$profile" > "${argc_file:-}" diff --git a/options/custom/scripts/default.nix b/options/custom/scripts/default.nix index 7ad8779..24afbfe 100644 --- a/options/custom/scripts/default.nix +++ b/options/custom/scripts/default.nix @@ -48,6 +48,8 @@ in { [ # Bash files with extension .sh (bash "audio" [ + argc + coreutils easyeffects libnotify ])