Advertisement
GegoXaren

shutdown.sh - Zenity baesd logout menu for Sway

May 25th, 2025 (edited)
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.13 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. ##################
  3. # Zenity based logout manager for sway.
  4. ##################
  5. ZENITY=zenity
  6. TIME_OUT=15
  7.  
  8. # Make sure Zentiy is floating
  9. swaymsg for_window "[app_id=\"zenity\"] floating enabled"
  10.  
  11. RESP=$($ZENITY --height=265 --width=100 \
  12.        --list --title="Shutdown?" \
  13.        --radiolist \
  14.        --column="ID" --column="Action" \
  15.        "1" "Shutdown" \
  16.        "2" "Reboot" \
  17.        "3" "Log out" \
  18.        "4" "Lock" \
  19.        "5" "Suspend" \
  20.        "6" "Hibernate")
  21.  
  22. # echo $RESP
  23.  
  24. function _countdown() {
  25.   local TIME=$1
  26.   local INTERVAL=$2
  27.   for (( t=$TIME; t>=0; t-=INTERVAL )); do
  28.     # Show time remaining in minutes / seconds
  29.       printf "# Time remaining: %d:%02d\n" $(( t/60 )) $(( t % 60 ));
  30.       echo "$(( ( ( TIME - t ) * 100 ) / TIME ))";
  31.       sleep "$INTERVAL";
  32.   done
  33. }
  34.  
  35. function _timer () {
  36.     local TITLE="$1"
  37.     _countdown $TIME_OUT 1 |\
  38.         zenity --progress --title="$TITLE"\
  39.         --percentage=0 --auto-close
  40.  
  41. }
  42.  
  43. function _shutdown () {
  44.    _timer "Shutting down..."
  45.    if [[ $? -eq 1 ]]; then
  46.        exit 1
  47.    fi
  48.    systemctl poweroff
  49. }
  50.  
  51.  
  52. function _reboot () {
  53.    _timer "Rebooting..."
  54.    if [[ $? -eq 1 ]]; then
  55.        exit 1
  56.    fi
  57.    systemctl reboot
  58. }
  59.  
  60. function _log_out () {
  61.    _timer "Logging out..."
  62.    if [[ $? -eq 1 ]]; then
  63.        exit 1
  64.    fi
  65.    swaymsg exit
  66. }
  67.  
  68. function _lock () {
  69.    _timer "Locking..."
  70.    if [[ $? -eq 1 ]]; then
  71.        exit 1
  72.    fi
  73.    swaymsg exec ~/.config/sway/lock.sh # https://pastebin.com/0KXr341y
  74. }
  75.  
  76. function _suspend() {
  77.    _timer "Suspening..."
  78.    if [[ $? -eq 1 ]]; then
  79.        exit 1
  80.    fi
  81.    echo "Suspending!"
  82.    systemctl suspend
  83. }
  84.  
  85. function _hibernate () {
  86.    _timer "Going inte hibernation..."
  87.    if [[ $? -eq 1 ]]; then
  88.        exit 1
  89.    fi
  90.    echo "Hibernating!"
  91.    systemctl hibernate
  92. }
  93.  
  94. case $RESP in
  95.     "Shutdown")
  96.         _shutdown
  97.         ;;
  98.     "Reboot")
  99.         _reboot
  100.         ;;
  101.     "Log out")
  102.         _log_out
  103.         ;;
  104.     "Lock")
  105.         _lock
  106.     ;;
  107.     "Suspend")
  108.         _suspend
  109.         ;;
  110.     "Hibernate")
  111.         _hibernate
  112.         ;;
  113.     *)
  114.         exit 1
  115. esac
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement