Skip to content

Instantly share code, notes, and snippets.

@ildar
Created July 3, 2025 13:31
Show Gist options
  • Save ildar/ef351cdf65e5b00c834fe7a36f75f59f to your computer and use it in GitHub Desktop.
Save ildar/ef351cdf65e5b00c834fe7a36f75f59f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Manual power manager :-\
command="$1"
delay=${2:-infinite}
set -euo pipefail
state=off
if systemd-inhibit --list | grep -q wayland_pm; then
state=on
fi
# shellcheck disable=SC3010
if [[ "$command" == "toggle_inhibit" ]]; then
if [[ "$state" == off ]]; then
systemd-inhibit \
--who=wayland_pm \
--why="script initiated" \
--mode=block \
sleep $delay >&2 &
else
pid=$(systemd-inhibit --list | grep wayland_pm)
pid=${pid// / }
pid=${pid#*"$USER" }
pid=${pid%% *}
kill $pid
fi
exit 0
fi
# shellcheck disable=SC3010
if [[ "$command" == "status_inhibit" ]]; then
if [[ "$state" == off ]]; then
echo "inhibit off"
else
echo "inhibit on"
fi
exit 0
fi
# shellcheck disable=SC3010
if [[ "$command" == "status_inhibit_icon" ]]; then
if [[ "$state" == off ]]; then
echo "💤"
else
echo "🍵"
fi
exit 0
fi
swayidle timeout 55 "light -O ; light -S 10" resume "light -I" &
swayidle timeout 65 "gtklock -b ~/.local/share/wallpapers/locksreen-bg.jpg" before-sleep "gtklock -b ~/.local/share/wallpapers/locksreen-bg.jpg" &
swayidle timeout 300 "LANG=C upower -i /org/freedesktop/UPower/devices/line_power_AC | grep online | egrep -q no$ && systemctl suspend" &
@ildar
Copy link
Author

ildar commented Jul 3, 2025

to use in ironbar add this to your config:

    - type: label
      label: ' {{2000:wayland_pm.sh status_inhibit_icon}} '
      name: 'idle-inhibitor'
      on_click_left: 'wayland_pm.sh toggle_inhibit 1800'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment