Update waybar config

This commit is contained in:
2026-02-18 00:14:12 -08:00
parent 833e4b51b0
commit 44145ecfde
6 changed files with 291 additions and 33 deletions

View File

@ -1,31 +1,60 @@
#!/usr/bin/env zsh
let is_active=0
systemctl --user --quiet is-active swayidle.service && is_active=1
zmodload zsh/datetime
zmodload zsh/mathfunc
setopt typeset_silent
local swayidle_state
(( is_active )) && swayidle_state='Enabled' || swayidle_state='Disabled'
local TIMES=(1m 5m 10m 15m 30m 1h 2h 4h 1d forever)
choice="$(fuzzel --index -d -p "Cur: ${swayidle_state} > " <<'EOF'
Enable
Disable
EOF
)"
local -a running_locks
(( ${?} != 0 )) && exit
() {
local IFS=$'\n '
running_locks=(${="$("${HOME}/scripts/cl/bin/list-manual-sleep-locks")"})
}
case "${choice}" in
0)
systemctl --user start swayidle.service
;;
1)
systemctl --user stop swayidle.service
;;
esac
let base_time=${EPOCHSECONDS}
for ((i = 2; i <= ${#running_locks}; i+=2)); do
local nsecs="${running_locks[i]}"
if [[ "${nsecs}" == infinity ]]; then
running_locks[i]="next reboot"
else
running_locks[i]=$(strftime -n '%H:%M:%S %b %-e' \
$(( base_time + nsecs )))
fi
done
if [[ "${XDG_CURRENT_DESKTOP}" == 'river' ]]; then
eww -c "${HOME}/.config/river/config/" update swayidle="$(( ! ${choice} ))"
pkill -RTMIN+3 waybar
elif [[ "${XDG_CURRENT_DESKTOP}" == 'Hyprland' ]]; then
pkill -SIGRTMIN+1 waybar
function is_valid_sleep_time() {
[[ "${1}" = forever ]] \
|| [[ "${1}" =~ ' *([0-9]+[smhd]? *)+' ]]
}
if (( ${#running_locks} )); then
# We have existing locks
local prompt plural_s
if (( ${#running_locks} > 2 )); then
let count_locks=$(( int(${#running_locks} / 2) ))
prompt="Locked by ${count_locks} locks until ${running_locks[2]}> "
plural_s='s'
else
prompt="Locked until ${running_locks[2]}> "
fi
local choice
choice="$(printf "Cancel lock${plural_s}\n" \
| fuzzel --dmenu --only-match --index -p "${prompt}")"
if (( ${?} == 0 )) && (( ${choice} == 0 )); then
systemctl --user stop 'manual-inhibit-sleep@*.service'
fi
else
# No locks
local choice
choice="$(printf '%s\n' ${TIMES} | fuzzel -d -p "Inhibit sleep for> ")"
if (( ${?} )); then
exit
elif is_valid_sleep_time "${choice}"; then
[[ "${choice}" == forever ]] && choice=infinity
systemctl --user start "manual-inhibit-sleep@${choice}.service"
else
printf 'Invalid sleep time: %s\n' "${choice}" 1>&2
fi
fi