dotfiles/scripts/pwr.sh

81 lines
1.4 KiB
Bash
Raw Normal View History

2022-07-17 12:55:05 +02:00
#!/bin/bash
2022-07-17 12:25:54 +02:00
function lock {
# Take a screenshot
scrot /tmp/screen_locked.png
# Pixellate it 10x
mogrify -scale 10% -scale 1000% /tmp/screen_locked.png
# Lock screen displaying this image.
i3lock -i /tmp/screen_locked.png
# delete Image
rm -f /tmp/screen_locked.png
}
function reboot {
sudo systemctl reboot
}
function shutdown {
2022-07-17 13:19:01 +02:00
sudo systemctl poweroff
2022-07-17 12:25:54 +02:00
}
function suspend {
lock
sudo systemctl suspend
}
function hibernate {
lock
2022-07-17 13:21:58 +02:00
sudo systemctl hibernate
2022-07-17 12:25:54 +02:00
}
2022-07-17 12:57:06 +02:00
function help {
2022-07-17 12:25:54 +02:00
echo "
Usage:
2022-07-17 13:04:15 +02:00
./pwr.sh [-r|-s|-sd|-hb]
2022-07-17 12:25:54 +02:00
Arguments:
-r, --reboot Reboot this system.
-s, --shutdown Shutdown this system.
-sd, --suspend Suspends this system.
-hb, --hibernate Hibernates this system.
-h, --help Displays this help.
"
}
function display_off {
# Turn the screen off
xset dpms force off
}
2022-07-17 12:57:06 +02:00
if [[ -n "$1" ]]; then
case "$1" in
--reboot | -r)
2022-07-21 14:51:16 +02:00
dunstify -u critical "reboot"
2022-07-21 15:23:37 +02:00
sleep 3
2022-07-17 12:57:06 +02:00
reboot
;;
--shutdown | -s)
2022-07-21 14:51:16 +02:00
dunstify -u critical "shutdown"
2022-07-21 15:23:37 +02:00
sleep 3
2022-07-17 12:57:06 +02:00
shutdown
;;
--suspend | -sd)
2022-07-21 14:51:16 +02:00
dunstify -u critical "suspend"
2022-07-21 15:23:37 +02:00
sleep 3
2022-07-17 12:57:06 +02:00
suspend
;;
--hibernate | -hb)
2022-07-21 14:51:16 +02:00
dunstify -u critical "hibernate"
2022-07-21 15:23:37 +02:00
sleep 3
2022-07-17 12:57:06 +02:00
hibernate
;;
--help | -h)
2022-07-17 12:57:38 +02:00
help
2022-07-17 12:57:06 +02:00
exit 0
;;
*)
2022-07-17 13:04:15 +02:00
echo -e "\e[31mUnbekannter Parameter!"
2022-07-17 12:57:06 +02:00
exit 1
esac
else
lock
2022-07-17 12:59:31 +02:00
sleep 60
display_off
2022-07-17 12:57:06 +02:00
fi