#!/usr/bin/env bash

args = "'$*' "
lines="-l 2"

first_prompt=""
opt1="Restart\nShutdown"
opt2="Yes\nNo"

ask() {
    answer="$( echo -e $1 | dmenu -i -p "$2" $lines $args )"
}

ask "$opt1" "$first_prompt"

case $answer in
    "Restart")
        ask "$opt2" "Are you sure?"
        if [[ $answer == "Yes" ]]; then
            systemctl reboot
        fi
        exit 0
        ;;
    "Shutdown")
        ask "$opt2" "Are you sure?"
        if [[ $answer == "Yes" ]]; then
            systemctl poweroff
        fi
        exit 0
        ;;
esac

exit 0