random-scripts/system-menu/system-menu.sh

36 lines
1.2 KiB
Bash
Raw Normal View History

2023-10-30 23:27:58 -07:00
#!/usr/bin/env zsh
2024-08-03 23:01:39 -07:00
function is-laptop-p {
[[ "${HOST}" == *-portable ]] || [[ "${HOST}" == *-laptop ]]
}
function is-desktop-p {
2024-08-03 23:04:36 -07:00
! is-laptop
2024-08-03 23:01:39 -07:00
}
2023-11-27 19:26:54 -08:00
pgrep swayidle && swayidle_state="Enabled" || swayidle_state="Disabled"
2023-11-27 18:26:14 -08:00
# Format: label action condition
local entries=('Select system sound output' 'select-sound-output.sh' 'true'
2023-11-27 19:26:54 -08:00
"Enable or disable system sleep (Current: ${swayidle_state})" 'system-sleep-menu.sh' 'true'
2024-08-03 23:01:39 -07:00
'Enable or disable TV' 'tv-power-menu.sh' 'is-desktop-p'
2023-11-27 18:26:14 -08:00
'Configure USB device access' 'usbguard-menu.py' 'pgrep usbguard-daemon'
2024-08-03 23:01:39 -07:00
'Power settings (restart and shutdown)' 'system-power-menu.sh' 'true'
'Login to captive portal protected WiFi' 'login-to-wifi.sh' 'is-laptop-p')
2023-11-27 18:26:14 -08:00
2023-11-27 19:26:54 -08:00
local entry_array=()
2023-11-27 21:24:02 -08:00
local enabled_entries=()
2023-11-27 18:26:14 -08:00
for ((i = 1; i <= ${#entries}; i+=3)); do
if eval "${entries[${i} + 2]}" >/dev/null 2>&1; then
2023-11-27 19:26:54 -08:00
entry_array[$((${i} / 3 + 1))]="${entries[${i}]}"
2023-11-27 21:24:02 -08:00
enabled_entries+=(${entries[@]:${i} - 1:3})
2023-11-27 18:26:14 -08:00
fi
done
2023-10-30 23:27:58 -07:00
local scripts_dir="$(dirname "$(realpath "${0}")")"
2023-11-27 19:26:54 -08:00
choice="$(printf '%s\n' ${entry_array} | fuzzel --index -d)"
2023-10-30 23:27:58 -07:00
(( ${?} != 0 )) && exit
2023-11-27 21:24:02 -08:00
eval "${scripts_dir}/${enabled_entries["${choice}" * 3 + 2]}"