desktop-config/roles/desktop-environment/templates/.local/bin/hyprhelpr.j2

95 lines
2.3 KiB
Plaintext
Raw Normal View History

#!/bin/bash
set -eu
background() {
swaybg \
{% for monitor in hostvars[ansible_hostname]['monitors'] -%}
-o "{{ monitor['desc'] }}" -i ~/.config/background/{{ monitor['background']['file'] }} -m {{ monitor['background']['mode'] }} {%- if not loop.last %}\{% endif %}
{% endfor %}
}
idle() {
swayidle -w \
timeout 180 '~/.local/bin/hyprhelpr lock' \
timeout 240 'hyprctl dispatch dpms off' \
resume 'hyprctl dispatch dpms on'
}
lock() {
if pgrep -x "swaylock" >/dev/null
then
echo "A instance of swaylock is already running."
exit 1
else
swaylock -f -e -s fill --indicator-radius 150 \
{% for monitor in hostvars[ansible_hostname]['monitors'] -%}
-i {{ monitor['output'] }}:~/.config/background/lock-{{ monitor['background']['file'] }} {%- if not loop.last %}\{% endif %}
{% endfor %}
fi
}
shutdown() {
sudo systemctl poweroff
}
reboot() {
sudo systemctl reboot
}
powermenu() {
PM_ACTION=$(printf "Shutdown\nReboot\nLock\nLogoff" | wofi --show=dmenu -i --width 200 --height 150)
if [ -n "$PM_ACTION" ]; then
case $PM_ACTION in
Shutdown)
shutdown
;;
Reboot)
reboot
;;
Lock)
lock
;;
Logoff)
hyprctl dispatch exit
;;
esac
fi
}
ACTION=$1
case $ACTION in
background)
background
;;
idle)
idle
;;
lock)
lock
;;
shutdown)
shutdown
;;
reboot)
reboot
;;
powermenu)
powermenu
;;
help | -h | --help)
echo "Usage: hyprhelpr <action> [parameters]"
echo "Available actions:"
echo " background Start swaybg with the configured backgrounds."
echo " idle Start swayidle with the configured actions."
echo " lock Lock the current session using swaylock."
echo " shutdown Shut down the system."
echo " reboot Reboot the system."
echo " powermenu Show wofi in dmenu mode with different power options"
echo " help Show this help text."
;;
*)
echo "Invalid action \"$ACTION\"."' Use "hyprhelpr help" to get help.'
exit 1
esac