diff --git a/dot_local/bin/executable_caffeine b/dot_local/bin/executable_caffeine new file mode 100644 index 0000000000000000000000000000000000000000..fbab06c106d81d3945b1339c20c086d3738017ad --- /dev/null +++ b/dot_local/bin/executable_caffeine @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +STATE_FILE="$XDG_CACHE_HOME/caffeine_state" +PID_FILE="$XDG_CACHE_HOME/caffeine.pid" + +caffeine_pid() { + systemd-inhibit --list | awk ' + $1 == "Caffeine" && $5 == "systemd-inhibit" { print $4 } + ' +} + +case $1 in +toggle) + PID="$(caffeine_pid)" + if [ -n "$PID" ]; then + kill "$PID" 2>/dev/null + rm -f "$STATE_FILE" "$PID_FILE" + xset +dpms s on + notify-send "Caffeine off" "System might go to sleep." + else + systemd-inhibit --what=idle:sleep:shutdown --mode=block \ + --who="Caffeine" --why="User-activated session protection" \ + sleep infinity & + echo $! >"$PID_FILE" + touch "$STATE_FILE" + xset -dpms s off s noblank + notify-send "Caffeine on" "System will stay awake." + fi + ;; +status) + if [ -n "$(caffeine_pid)" ]; then + echo "󰅶" + else + echo "󰾪" + fi + ;; +esac