Upgrade system menu features

This commit is contained in:
2023-10-30 23:27:58 -07:00
parent cf73e8a8ed
commit a502b72299
3 changed files with 39 additions and 2 deletions

View File

@ -0,0 +1,28 @@
#!/usr/bin/env zsh
local info="$(pactl list sinks)"
local default_name="$(pactl info | grep -Po '(?<=Default Sink: ).+')"
local ids=(${(@f)"$(echo "${info}" | grep -Po '(?<=Sink #).+')"})
local names=(${(@f)"$(echo "${info}" | grep -Po '(?<=Name: ).+')"})
local descs=(${(@f)"$(echo "${info}" | grep -Po '(?<=Description: ).+')"})
local default_id=""
local query_string=""
for ((i = 1; i <= "${#ids}"; ++i)); do
if [[ "${names[${i}]}" == "${default_name}" ]]; then
default_id="${ids[${i}]}"
fi
query_string+="${ids[${i}]}: ${descs[${i}]} (${names[${i}]})\n"
done
[[ -v WAYLAND_DISPLAY ]] \
&& prompt_cmd=("fuzzel" "-dp" "${default_id}> ") \
|| prompt_cmd=("dmenu" "-p" "${default_id}:")
local choice
choice="$(echo "${query_string%"\n"}" | ${prompt_cmd})"
if (( "${?}" != 0 )); then
exit
fi
local selected_id="$(echo "${choice}" | grep -Eo '^[0-9]+')"
pactl set-default-sink "${selected_id}"
local selected_name="$(echo "${choice}" \
| cut -c "$(("${#selected_id}" + 3))-" \
| grep -Po '^.+(?= \()')"
notify-send 'Output Device' "${selected_name} (${selected_id})"

20
system-menu/system-menu.sh Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env zsh
local scripts_dir="$(dirname "$(realpath "${0}")")"
choice="$(fuzzel --index -d <<'EOF'
Select system sound output
Power settings (restart and shutdown)
EOF
)"
(( ${?} != 0 )) && exit
echo $choice
case "${choice}" in
0)
"${scripts_dir}/select-sound-output.sh"
;;
1)
"${scripts_dir}/system-power-menu.sh"
;;
esac

View File

@ -0,0 +1,17 @@
#!/usr/bin/env zsh
choice="$(fuzzel --index -d <<'EOF'
Shutdown
Restart
EOF
)"
(( ${?} != 0 )) && exit
case "${choice}" in
0)
poweroff
;;
1)
restart
;;
esac