From 6964a43e42e7ab7b158167992f2c23fdd7368daa Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Mon, 27 Nov 2023 19:26:54 -0800 Subject: [PATCH] Add system-sleep-menu.sh --- system-menu/system-menu.sh | 13 +++++++------ system-menu/system-sleep-menu.sh | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100755 system-menu/system-sleep-menu.sh diff --git a/system-menu/system-menu.sh b/system-menu/system-menu.sh index e6dd235..fd1fe44 100755 --- a/system-menu/system-menu.sh +++ b/system-menu/system-menu.sh @@ -1,22 +1,23 @@ #!/usr/bin/env zsh +pgrep swayidle && swayidle_state="Enabled" || swayidle_state="Disabled" + # Format: label action condition local entries=('Select system sound output' 'select-sound-output.sh' 'true' + "Enable or disable system sleep (Current: ${swayidle_state})" 'system-sleep-menu.sh' 'true' 'Configure USB device access' 'usbguard-menu.py' 'pgrep usbguard-daemon' 'Power settings (restart and shutdown)' 'system-power-menu.sh' 'true') -local fuzzel_input="" -declare -A entry_map +local entry_array=() for ((i = 1; i <= ${#entries}; i+=3)); do if eval "${entries[${i} + 2]}" >/dev/null 2>&1; then - entry_map["${entries[${i}]}"]="${entries[${i} + 1]}" - fuzzel_input+="${entries[${i}]}\n" + entry_array[$((${i} / 3 + 1))]="${entries[${i}]}" fi done local scripts_dir="$(dirname "$(realpath "${0}")")" -choice="$(echo -n "${fuzzel_input}" | fuzzel -d)" +choice="$(printf '%s\n' ${entry_array} | fuzzel --index -d)" (( ${?} != 0 )) && exit -eval "${scripts_dir}/${entry_map["${choice}"]}" +eval "${scripts_dir}/${entries["${choice}" * 3 + 2]}" diff --git a/system-menu/system-sleep-menu.sh b/system-menu/system-sleep-menu.sh new file mode 100755 index 0000000..24ac5fd --- /dev/null +++ b/system-menu/system-sleep-menu.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env zsh + +pgrep swayidle && swayidle_state="Enabled" || swayidle_state="Disabled" + +choice="$(fuzzel --index -d -p "Cur: ${swayidle_state} > " <<'EOF' +Enable +Disable +EOF +)" + +(( ${?} != 0 )) && exit + +case "${choice}" in + 0) + swayidle & + ;; + 1) + pkill swayidle + ;; +esac