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

118 lines
3.1 KiB
Plaintext
Raw Normal View History

#!/bin/bash
set -eu
background() {
swaybg \
2024-05-27 23:37:19 +02:00
{% 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 \
2024-05-27 23:37:19 +02:00
{% 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
}
2024-10-12 18:11:35 +02:00
screenshot() {
ACTION=$(printf "Area\nWindow\nScreen" | wofi --show=dmenu -i --width 200 --height 150)
if [ -n "$ACTION" ]; then
case $ACTION in
Area)
grim -g "$(slurp)" - | swappy -f -
;;
Window)
grim -g "$(hyprctl clients -j | jq -r ".[] | select(.workspace.id | IN(["$(hyprctl monitors -j | jq '.[].activeWorkspace.id' | xargs | sed -e 's/ /,/g')"][]))" | jq -r ".at,.size" | jq -s "add" | jq '_nwise(4)' | jq -r '"\(.[0]),\(.[1]) \(.[2])x\(.[3])"' | slurp)" - | swappy -f -
;;
Screen)
grim -g "$(slurp -o)" - | swappy -f -
;;
esac
fi
}
ACTION=$1
case $ACTION in
background)
background
;;
idle)
idle
;;
lock)
lock
;;
shutdown)
shutdown
;;
reboot)
reboot
;;
powermenu)
powermenu
;;
2024-10-12 18:11:35 +02:00
screenshot)
screenshot
;;
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"
2024-10-12 18:11:35 +02:00
echo " screenshot Show wofi in dmenu mode with different screenshot options"
echo " help Show this help text."
;;
*)
echo "Invalid action \"$ACTION\"."' Use "hyprhelpr help" to get help.'
exit 1
esac