#!/bin/bash
# /usr/bin/i3exit

logind=/usr/bin/systemctl || logind=/usr/bin/loginctl

case "$1" in
    lock)
        /usr/bin/betterlockscreen -l
        ;;

    suspend)
        /usr/bin/betterlockscreen -l & /usr/bin/sleep 0.5; /usr/bin/systemctl suspend
        ;;

    switch_user)
        /usr/bin/dm-tool switch-to-greeter
        ;;

    logout)
        /usr/bin/i3-msg exit
        ;;

    hibernate)
        /usr/bin/betterlockscreen -l & /usr/bin/sleep 0.5; /usr/bin/systemctl hibernate
        ;;

    reboot)
        /usr/bin/systemctl reboot
        ;;

    shutdown)
        /usr/bin/systemctl poweroff
        ;;

    *)
        echo "== ! i3exit: missing or invalid argument ! =="
        echo "Try again with: lock | suspend | switch_user | logout | hibernate | reboot | shutdown"
        exit 2

esac

exit 0
