Skip to content

Instantly share code, notes, and snippets.

@blueyed
Created July 5, 2015 21:44
Show Gist options
  • Save blueyed/84a578b575ef07e9635c to your computer and use it in GitHub Desktop.
Save blueyed/84a578b575ef07e9635c to your computer and use it in GitHub Desktop.

Revisions

  1. blueyed created this gist Jul 5, 2015.
    47 changes: 47 additions & 0 deletions logout.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/bin/sh

    # close stdin
    exec <&-

    # ACTION=$(zenity --title "Select logout action" --text "How to quit?" --height=250 --list \
    # --hide-header --hide-column=1 --column=action --column=desc \
    # suspend "Suspend" \
    # hybrid-sleep "Hybrid sleep" \
    # hibernate "Hibernate" \
    # reboot "Reboot" \
    # shutdown "Shutdown" \
    # switch-user "Switch user" \
    # logout "Logout" \
    # lock "Lock screen")

    # ACTION=$(printf 'suspend\nhybrid-sleep\nhibernate\nreboot\nshutdown\nswitch-user\nlogout\nlock' \
    # | dmenu -p "How do you want to quit?")
    ACTION=$(printf 'suspend|hybrid-sleep|hibernate|reboot|shutdown|switch-user|logout|lock|abort|' \
    | rofi -dmenu -sep '|' -p "How do you want to quit? " -only-match)

    if [ -n "${ACTION}" ];then
    case $ACTION in
    switch-user)
    # Lightdm: detect via XDG_SEAT_PATH
    dm-tool switch-to-greeter
    # for gdm: gdmflexiserver --startnew
    ;;
    hybrid-sleep) systemctl hybrid-sleep ;;
    suspend)
    systemctl suspend
    /usr/bin/slock
    ;;
    hibernate) systemctl hibernate ;;
    reboot)
    zenity --question --text "Are you sure?" \
    && systemctl reboot ;;
    shutdown)
    zenity --question --text "Are you sure?" \
    && systemctl poweroff ;;
    logout)
    zenity --question --text "Are you sure?" \
    && gnome-session-quit --logout --no-prompt ;;
    lock) slock ;;
    abort) ;;
    esac
    fi