#!/bin/bash

# omarchy:summary=Set the default audio input and move active streams
# omarchy:args=<node-id> <source-name>
# omarchy:examples=omarchy audio input set default 43 alsa_input.pci-0000_00_1f.3.analog-stereo

node_id=${1:-}
source_name=${2:-}

if [[ -z $node_id || -z $source_name ]]; then
  echo "Usage: omarchy-audio-input-set-default <node-id> <source-name>" >&2
  exit 1
fi

wpctl set-default "$node_id" 2>/dev/null || true
pactl set-default-source "$source_name" 2>/dev/null || true

pactl list short source-outputs 2>/dev/null | awk '{ print $1 }' | while read -r output; do
  [[ -n $output ]] && pactl move-source-output "$output" "$source_name" 2>/dev/null || true
done
