#!/usr/bin/env sh

case "$(printf "new\nstop\nrestart\neshell\nmail" | dmenu -p "eserver: ")" in
    "restart")
        emacsclient --eval "(save-buffers-kill-emacs)" && \
            suctl restart emacs && \
            notify-send "eselect: Restarted server";;
    "stop")
        emacsclient --eval "(save-buffers-kill-emacs)" && \
            suctl stop emacs && \
            notify-send "eselect: Halted server";;
    "new")
        notify-send "eselect: Launching Emacs" && \
            suctl start emacs && \
            emacsclient -c -a "emacs";;
    "eshell")
        notify-send "eselect: Launching Eshell" && \
            suctl start emacs && \
            emacsclient -c -a "emacs" --eval "(progn (eshell) (delete-other-windows))";;
    "mail")
        notify-send "eselect: Launching notmuch" && \
            suctl start emacs && \
            emacsclient -c -a "emacs" --eval "(progn (notmuch) (delete-other-windows))";;
esac
