From d3c89f89f6b316d335de9ab089d8d0773ae6deca Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Thu, 2 Jul 2026 07:04:59 +0200 Subject: [PATCH] Rofi scripts for extra menus --- scripts/bin/audioswitch | 65 +++++++++++++++++++++++++++++++++++++++++ scripts/bin/powermenu | 24 +++++++++++++++ 2 files changed, 89 insertions(+) create mode 100755 scripts/bin/audioswitch create mode 100755 scripts/bin/powermenu diff --git a/scripts/bin/audioswitch b/scripts/bin/audioswitch new file mode 100755 index 0000000..4dc1faf --- /dev/null +++ b/scripts/bin/audioswitch @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +# rofi-audio-switch: pick a PulseAudio/PipeWire sink via rofi + +set -euo pipefail + +# Get list of sinks: index, name, description +mapfile -t sinks < <(pactl list sinks | awk -F': ' ' + /^Sink #/ { idx=$2 } + /Name:/ { name=$2 } + /Description:/ { desc=$2; print idx"\t"name"\t"desc } +') + +if [ "${#sinks[@]}" -eq 0 ]; then + notify-send "Audio Switch" "No sinks found" + exit 1 +fi + +current_sink=$(pactl get-default-sink) + +# Build rofi menu: show description, mark current with a star +menu="" +for line in "${sinks[@]}"; do + name=$(echo "$line" | cut -f2) + desc=$(echo "$line" | cut -f3) + if [ "$name" = "$current_sink" ]; then + menu+="* $desc\n" + else + menu+=" $desc\n" + fi +done + +chosen=$(echo -e "$menu" | rofi -dmenu -i -p "Audio Output" -markup-rows \ + -theme-str 'listview { lines: 3; }' \ + -theme-str 'window { height: 220px; }') + +[ -z "$chosen" ] && exit 0 + +# Strip the leading marker to match description text +chosen_desc=$(echo "$chosen" | sed 's/^[* ] //') + +# Find matching sink name for that description +target_name="" +for line in "${sinks[@]}"; do + desc=$(echo "$line" | cut -f3) + if [ "$desc" = "$chosen_desc" ]; then + target_name=$(echo "$line" | cut -f2) + break + fi +done + +if [ -z "$target_name" ]; then + notify-send "Audio Switch" "Could not resolve selection" + exit 1 +fi + +# Set as default sink +pactl set-default-sink "$target_name" + +# Move all currently running streams to the new sink +mapfile -t inputs < <(pactl list short sink-inputs | cut -f1) +for input in "${inputs[@]}"; do + pactl move-sink-input "$input" "$target_name" +done + +notify-send "Audio Switch" "Switched to: $chosen_desc" diff --git a/scripts/bin/powermenu b/scripts/bin/powermenu new file mode 100755 index 0000000..36a0b18 --- /dev/null +++ b/scripts/bin/powermenu @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# rofi-power-menu: logout / restart / shutdown via rofi + +set -euo pipefail + +options=" Logout\n Restart\n Shutdown" + +chosen=$(echo -e "$options" | rofi -dmenu -i -p "Power" -markup-rows \ + -theme-str 'listview { lines: 3; }' \ + -theme-str 'window { height: 240px; }') + +[ -z "$chosen" ] && exit 0 + +case "$chosen" in + *Logout*) + awesome-client "awesome.quit()" 2>/dev/null || echo "awesome.quit()" | awesome-client + ;; + *Restart*) + loginctl reboot + ;; + *Shutdown*) + loginctl poweroff + ;; +esac