diff --git a/pkgs/change-audio/change-audio b/pkgs/change-audio/change-audio index 836e0c1..5bb1588 100755 --- a/pkgs/change-audio/change-audio +++ b/pkgs/change-audio/change-audio @@ -2,22 +2,61 @@ set -euo pipefail -if [ "$1" = "up" ]; then - upDown="-i" -else - upDown="-d" -fi +NOTIFY=( + notify-send + -u low + -h string:x-canonical-private-synchronous:change-audio +) -pamixer --allow-boost "$upDown" "$2" -newVolume="$(pamixer --get-volume || true)" -[ "$(pamixer --get-volume-human)" = "muted" ] && isMuted=true +do_change_volume() { + if [ "$1" = "up" ]; then + upDown="-i" + else + upDown="-d" + fi -MSG="Set volume to $newVolume%" -if [ "${isMuted:-false}" = true ]; then - MSG="$MSG (muted)" -fi + pamixer --allow-boost "$upDown" "$2" + newVolume="$(pamixer --get-volume || true)" + [ "$(pamixer --get-volume-human)" = "muted" ] && isMuted=true -notify-send -u low \ - -h string:x-canonical-private-synchronous:change-audio \ - -h "int:value:$newVolume" \ - -- "$MSG" + MSG="Set volume to $newVolume%" + if [ "${isMuted:-false}" = true ]; then + MSG="$MSG (muted)" + fi + "${NOTIFY[@]}" \ + -h "int:value:$newVolume" \ + -- "$MSG" +} + +do_toggle() { + args=() + if [ "${2:-audio}" = mic ]; then + args+=(--default-source) + MSG="Toggled microphone" + else + MSG="Toggled audio output" + fi + + pamixer "${args[@]}" --toggle-mute + + if [ "$(pamixer "${args[@]}" --get-mute)" = true ]; then + MSG="$MSG (muted)" + else + MSG="$MSG (unmuted)" + fi + + "${NOTIFY[@]}" -- "$MSG" +} + +case "$1" in + up|down) + do_change_volume "$@" + ;; + toggle) + do_toggle "$@" + ;; + *) + echo "No suche option '$1'" >&2 + exit 1 + ;; +esac diff --git a/pkgs/change-audio/default.nix b/pkgs/change-audio/default.nix index de050ff..bf0f45c 100644 --- a/pkgs/change-audio/default.nix +++ b/pkgs/change-audio/default.nix @@ -1,7 +1,7 @@ { lib, libnotify, makeWrapper, pamixer, shellcheck, stdenvNoCC }: stdenvNoCC.mkDerivation rec { pname = "change-audio"; - version = "0.1.2"; + version = "0.2.0"; src = ./change-audio;