Add Arch Wayland dotfiles: sway/waybar/kitty/nvim/zsh, idempotent installer
Auto-adapts sway workspace routing to however many monitors are connected (laptop vs. desktop) instead of hardcoding output names.
This commit is contained in:
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
source_ids=()
|
||||
current_index=-1
|
||||
|
||||
while IFS=$'\t' read -r id is_default; do
|
||||
[[ -n "$id" ]] || continue
|
||||
source_ids+=("$id")
|
||||
[[ "$is_default" == true ]] && current_index=$((${#source_ids[@]} - 1))
|
||||
done < <(
|
||||
wpctl status -n | awk '
|
||||
/^Audio$/ {in_audio = 1; next}
|
||||
/^Video$/ {in_audio = 0; in_sources = 0}
|
||||
in_audio && /Sources:/ {in_sources = 1; next}
|
||||
/Filters:/ {in_sources = 0}
|
||||
in_audio && in_sources && match($0, /[0-9]+\./) {
|
||||
id = substr($0, RSTART, RLENGTH - 1)
|
||||
print id "\t" (index($0, "*") ? "true" : "false")
|
||||
}
|
||||
'
|
||||
)
|
||||
|
||||
((${#source_ids[@]} > 0)) || exit 0
|
||||
next_index=$(((current_index + 1) % ${#source_ids[@]}))
|
||||
next_source_id="${source_ids[$next_index]}"
|
||||
wpctl set-default "$next_source_id"
|
||||
|
||||
source_name=$(
|
||||
wpctl inspect "$next_source_id" \
|
||||
| awk -F' = ' '/node.nick/ {gsub(/^"|"$/, "", $2); print $2; exit}'
|
||||
)
|
||||
[[ -n "$source_name" ]] || source_name="Input $next_source_id"
|
||||
notify-send -a Waybar -u low -r 9102 "Audio input changed" "$source_name"
|
||||
Reference in New Issue
Block a user