(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

@@ -48,7 +48,7 @@ alias firefox='librewolf'
## run script to setup default tmux session and then attach the session
## attaching the session needs to be done from the calling shell, otherwise
## the setup script will only terminate after detaching or killing the session
alias dmux='default-tmux-session && tmux attach'
alias dmux='bash default-tmux-session.sh && tmux attach'
alias tks='tmux kill-session'
alias tma='tmux attach'
@@ -80,10 +80,11 @@ source ~/.bash_alias
## source custom functions for specific purposes
script_path=${HOME}/dotfiles/scripts/
source_list=()
source_list+=("${script_path}/navigate_bash_setup")
source_list+=("${script_path}/fzf-bash-history")
source_list+=("${script_path}/navigate_bash_setup.sh")
source_list+=("${script_path}/fzf-bash-history.sh")
source_list+=("${script_path}/colors.sh")
source_list+=("${script_path}/dunst.sh")
source_list+=("${script_path}/select-audio-sink.sh")
## source qmk setup script
# source /home/scbj/repos/qmk_firmware/util/qmk_tab_complete.sh

View File

@@ -167,7 +167,7 @@ bindsym $mod+s exec --no-startup-id maim -su | xclip -selection clipboard
bindsym $mod+Shift+s exec --no-startup-id maim -su "/home/${USER}/Pictures/screenshots/$(date '+%Y%m%d_%H%M%S').png"
# open pavucontrol
bindsym $mod+a exec --no-startup-id pavucontrol
bindsym $mod+a exec bash select-audio-sink.sh
# Use pactl to adjust volume in PulseAudio.
set $refresh_i3status killall -SIGUSR1 i3status

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