Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- ##################
- # Zenity based logout manager for sway.
- ##################
- ZENITY=zenity
- TIME_OUT=15
- # Make sure Zentiy is floating
- swaymsg for_window "[app_id=\"zenity\"] floating enabled"
- RESP=$($ZENITY --height=265 --width=100 \
- --list --title="Shutdown?" \
- --radiolist \
- --column="ID" --column="Action" \
- "1" "Shutdown" \
- "2" "Reboot" \
- "3" "Log out" \
- "4" "Lock" \
- "5" "Suspend" \
- "6" "Hibernate")
- # echo $RESP
- function _countdown() {
- local TIME=$1
- local INTERVAL=$2
- for (( t=$TIME; t>=0; t-=INTERVAL )); do
- # Show time remaining in minutes / seconds
- printf "# Time remaining: %d:%02d\n" $(( t/60 )) $(( t % 60 ));
- echo "$(( ( ( TIME - t ) * 100 ) / TIME ))";
- sleep "$INTERVAL";
- done
- }
- function _timer () {
- local TITLE="$1"
- _countdown $TIME_OUT 1 |\
- zenity --progress --title="$TITLE"\
- --percentage=0 --auto-close
- }
- function _shutdown () {
- _timer "Shutting down..."
- if [[ $? -eq 1 ]]; then
- exit 1
- fi
- systemctl poweroff
- }
- function _reboot () {
- _timer "Rebooting..."
- if [[ $? -eq 1 ]]; then
- exit 1
- fi
- systemctl reboot
- }
- function _log_out () {
- _timer "Logging out..."
- if [[ $? -eq 1 ]]; then
- exit 1
- fi
- swaymsg exit
- }
- function _lock () {
- _timer "Locking..."
- if [[ $? -eq 1 ]]; then
- exit 1
- fi
- swaymsg exec ~/.config/sway/lock.sh # https://pastebin.com/0KXr341y
- }
- function _suspend() {
- _timer "Suspening..."
- if [[ $? -eq 1 ]]; then
- exit 1
- fi
- echo "Suspending!"
- systemctl suspend
- }
- function _hibernate () {
- _timer "Going inte hibernation..."
- if [[ $? -eq 1 ]]; then
- exit 1
- fi
- echo "Hibernating!"
- systemctl hibernate
- }
- case $RESP in
- "Shutdown")
- _shutdown
- ;;
- "Reboot")
- _reboot
- ;;
- "Log out")
- _log_out
- ;;
- "Lock")
- _lock
- ;;
- "Suspend")
- _suspend
- ;;
- "Hibernate")
- _hibernate
- ;;
- *)
- exit 1
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement