Initial commit

This commit is contained in:
2026-08-10 10:45:29 -04:00
commit b2ec67a71b
5 changed files with 350 additions and 0 deletions
Executable
+95
View File
@@ -0,0 +1,95 @@
#!/bin/sh
#pacmd set-default-sink alsa_output.usb-Logitech_Logitech_G933_Gaming_Wireless_Headset-00.analog-stereo
#pacmd set-default-source alsa_input.usb-Logitech_Logitech_G933_Gaming_Wireless_Headset-00.analog-mono
set -e
QUDELIX_SINK="alsa_output.usb-QTIL_Qudelix-5K_USB_DAC_ABCDEF0123456789-00.analog-stereo"
SPEAKER_SINK="alsa_output.pci-0000_0f_00.4.3.iec958-stereo"
STAGE_SINK="alsa_output.usb-ACTIONS_Stage_V2-00.analog-stereo"
BOSE_SINK="bluez_output.78_2B_64_CE_04_03.1"
FRACTAL_SINK="alsa_output.usb-Fractal_Fractal_Scape_Dongle_00000000911AD5560372-00.analog-stereo"
SNAPCAST_SINK="snapcast_out"
YETI_SOURCE="alsa_input.usb-Blue_Microphones_Yeti_Nano_2231SQ0017G8_888-000476140106-00.analog-stereo"
NOISETORCH_SOURCE="NoiseTorch Microphone for Yeti Nano"
FRACTAL_SOURCE="alsa_input.usb-Fractal_Fractal_Scape_Dongle_00000000911AD5560372-00.mono-fallback"
switchAudio() {
case "$1" in
"-s")
#echo fractal
echo -e "fractal\0icon\x1faudio-headphones"
#echo snapcast
echo -e "snapcast"
#echo -en "Firefox\0icon\x1ffirefox" | fuzzel --dmenu
echo -e "stage\0icon\x1faudio-speakers"
#echo "stage"
echo -e "bose\0icon\x1fbluetooth"
#echo "qudelix"
echo -e "qudelix\0icon\x1faudio-headphones"
exit 0;
;;
"qudelix")
local sink="$QUDELIX_SINK"
# local source="$NOISETORCH_SOURCE"
local source="$YETI_SOURCE"
;;
"speakers")
local sink="$SPEAKER_SINK"
local source="$YETI_SOURCE"
;;
"stage")
local sink="$STAGE_SINK"
local source="$YETI_SOURCE"
;;
"bose")
local sink="$BOSE_SINK"
local source="$YETI_SOURCE"
;;
"fractal")
local sink="$FRACTAL_SINK"
local source="$FRACTAL_SOURCE"
;;
"snapcast")
local sink="$SNAPCAST_SINK"
local source="$FRACTAL_SOURCE"
;;
esac;
local sourceCommand="pactl move-source-output {} $source"
local sinkCommand="pactl move-sink-input {} $sink"
pactl set-default-sink $sink
pactl list | grep -o -E 'Sink Input #([0-9]+)' | cut -d"#" -f2 | xargs -I '{}' $sinkCommand
#pactl list | grep -o -E 'Source Output #([0-9]+)' | cut -d"#" -f2 | xargs -I '{}' $sourceCommand
pactl set-default-source $source
echo $1 > $HOME/.last_audio
notify-send -a "Audio" "Switched to $1"
}
nextAudio() {
local last_audio=$(cat $HOME/.last_audio)
case "$last_audio" in
"fractal")
local next="speakers"
;;
"speakers")
local next="fractal"
;;
*)
local next="fractal"
;;
esac;
switchAudio $next
}
case "$1" in
"next")
nextAudio
;;
*)
switchAudio $1
;;
esac;
Executable
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/nu
let launcher_apps = open $"($env.HOME)/.config/switchrun/apps.nuon"
def lookup_window_id [running_apps, app_id] {
let matches = $running_apps | where app_id == $app_id
if ($matches | is-empty) {
"none"
} else {
$matches | get id | first | into string
}
}
def switch_to [target_window_id: string] {
let focus_cmd = {Action: { FocusWindow: { id: ($target_window_id | into int ) } } }
$focus_cmd | to json -r | socat STDIO $env.NIRI_SOCKET
}
def launch [target_app_id: string] {
let app = (
$launcher_apps |
where app_id == $target_app_id |
first
)
print $app.exec
print ...$app.args
if $app != null { run-external $app.exec ...$app.args} else { print "no exec found" }
}
def main [target_app_id: string] {
let running_apps = niri msg --json windows | from json
let matches = $running_apps | where app_id == $target_app_id
print $matches
if ($matches | is-empty) {
launch $target_app_id
} else {
let focused_matches = $matches | enumerate | where item.is_focused == true | get index
if ($focused_matches | is-empty) {
switch_to (($matches | first | get id) | into string)
} else {
# In the event of multiple matches, switch to the one after the focused one - wrapping around
# That way we will cycle through them
let target_index = ($focused_matches | first) - 1
print $target_index
print ($matches | length)
let target_window = if ($target_index < 0) { $matches | last } else { ($matches | get $target_index) }
switch_to ($target_window.id | into string)
}
}
}
def "main list" [tag?: string] {
let running_apps = niri msg --json windows | from json
# Optionally narrow to apps carrying the requested tag.
let filtered = (if ($tag | is-empty) {
$launcher_apps
} else {
$launcher_apps | where { |app| ($tag in ($app.tags? | default [])) }
})
if ($filtered | is-empty) {
print $"No applications match tag '($tag)'"
return
}
let apps = $filtered | each { |app| $app | insert window_id { lookup_window_id $running_apps $app.app_id } }
# if the selected app_id is running then
# focus it by its window id (first window id for that app id is fine)
# if it's not running then launch it using the app's desktop entry
#
let app_lines = $apps | each { $"($in.name) - [($in.app_id), ($in.window_id)]" }
let prompt = if ($tag | is-empty) { "Launch/Switch" } else { $"Launch/Switch [($tag)]" }
let selection = $app_lines | each { echo $in } | str join "|" | rofi -dmenu -i -p $prompt -sep "|"
let parsed = $selection | parse "{name} - [{app_id}, {window_id}]" | first
let match = $apps | where app_id == $parsed.app_id | first
if $parsed.window_id == "none" { launch $match.app_id } else { switch_to $match.window_id }
}