(scripts) added script to switch audio sink, renamed scripts to "*.sh"

This commit is contained in:
quak
2025-05-28 21:44:32 +02:00
parent f446c6ed8d
commit 3cebb6014d
6 changed files with 39 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
function __search-history {
current_line="${READLINE_LINE}"

33
scripts/select-audio-sink.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/env bash
select_audio_sink() {
sinks="$(pactl list sinks | grep -iozP "(?s)(?<=Properties:).*?(?=Ports:)" | tr -d '\0')"
IFS=$(echo -en "\n\b")
ids=($(echo "${sinks}" | grep -io -P "(?<=object.serial = ).*$"))
names=($(echo "${sinks}" | grep -ioP "(?<=device\.description = ).*$"))
unset IFS
if [[ "${#ids[@]}" != "${#names[@]}" ]]; then
echo "ERROR: #ids (${#ids[@]}) != #names (${#names[@]})"
return 0
fi
selection="$(printf "%s\n" "${names[@]//\"/}" | rofi -dmenu)"
unset number
for n in ${!names[@]}; do
if [[ "${names[$n]}" == *"${selection}"* ]]; then
number=$n
fi
done
if [[ -z "${number}" ]]; then
echo "something went wrong.."
return 0
fi
pactl set-default-sink ${ids[$number]//\"/}
}
select_audio_sink