diff options
Diffstat (limited to 'nixos/scripts/dm-pipewire-out-switcher')
-rwxr-xr-x | nixos/scripts/dm-pipewire-out-switcher | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/nixos/scripts/dm-pipewire-out-switcher b/nixos/scripts/dm-pipewire-out-switcher new file mode 100755 index 0000000..8023671 --- /dev/null +++ b/nixos/scripts/dm-pipewire-out-switcher @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# Script name: dm-pipewire-out-switcher +# Description: Switch default output for pipewire. +# Dependencies: dmenu, fzf, rofi, pipewire, jq, pactl +# GitLab: https://www.gitlab.com/dwt1/dmscripts +# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE +# Contributors: Simon Ingelsson +# Derek Taylor + +# Set with the flags "-e", "-u","-o pipefail" cause the script to fail +# if certain things happen, which is a good thing. Otherwise, we can +# get hidden bugs that are hard to discover. +set -euo pipefail + +# shellcheck disable=SC1091 +source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null + +source_dmscripts_configs + +if configs_are_different; then + echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE" + sleep 1 +fi + +get_default_sink() { + pactl --format=json info | jq -r .default_sink_name +} +get_all_sinks() { + pactl --format=json list short sinks \ + | current=$(get_default_sink) jq -r '.[] | if .name == env.current then .state="* " else .state="" end | .state + .name' +} + +main() { + choice=$(printf '%s\n' "$(get_all_sinks)" \ + | sort \ + | ${MENU} 'Sink: ') || exit 1 + + if [ "$choice" ]; then + if [[ "${choice}" == "* $(get_default_sink)" ]]; then + exit 0 + fi + pactl set-default-sink "${choice}" + notify-send "Sink is now: ${choice}" + else + echo "Program terminated." && exit 0 + fi +} + +MENU="$(get_menu_program "$@")" +[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main |