2023-11-27 19:26:54 -08:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
|
2024-05-16 04:18:17 -07:00
|
|
|
local CACHE_PATH="${HOME}/.cache/system-sleep-menu"
|
|
|
|
|
|
|
|
pgrep swayidle >/dev/null 2>&1 \
|
|
|
|
&& swayidle_state="Enabled" \
|
|
|
|
|| swayidle_state="Disabled"
|
2023-11-27 19:26:54 -08:00
|
|
|
|
|
|
|
choice="$(fuzzel --index -d -p "Cur: ${swayidle_state} > " <<'EOF'
|
|
|
|
Enable
|
|
|
|
Disable
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
|
|
|
|
(( ${?} != 0 )) && exit
|
|
|
|
|
|
|
|
case "${choice}" in
|
|
|
|
0)
|
2024-05-16 04:18:17 -07:00
|
|
|
if [[ "${swayidle_state}" == 'Disabled' ]]; then
|
|
|
|
local cmd_cache=(${(0)"$(<"${CACHE_PATH}")"})
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
cd "${cmd_cache[1]}"
|
|
|
|
eval "${cmd_cache[2]}" &
|
|
|
|
)
|
|
|
|
fi
|
2023-11-27 19:26:54 -08:00
|
|
|
;;
|
|
|
|
1)
|
2024-05-16 04:18:17 -07:00
|
|
|
pgrep_output=(${(ps: :)"$(pgrep -fa swayidle)"})
|
|
|
|
if [[ "${swayidle_state}" = 'Enabled' ]]; then
|
|
|
|
local si_pid="${pgrep_output[1]}"
|
|
|
|
local si_pwd="$(readlink "/proc/${si_pid}/cwd")"
|
|
|
|
local si_cmd="${pgrep_output:1}"
|
|
|
|
printf '%s\0%s' "${si_pwd}" "${si_cmd}" >"${CACHE_PATH}"
|
|
|
|
pkill swayidle
|
|
|
|
fi
|
2023-11-27 19:26:54 -08:00
|
|
|
;;
|
|
|
|
esac
|