system-menu.sh 1.2 KB

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