2020-12-01

Login Menu with dialog

linux   index

Most standard Linux distribution installations come with a Display Manager, usually tied to the desktop environment. Like GDM for Gnome, LXDM for LXDE, etc. There are also a few lighter ones, like XDM/LightDM…

But, not everyone likes a full Desktop Environment, or even a Display Manager. Some simply login on the shell and run startx.

However, a Display Manager serves another purpose as well, that is selecting which environment to log into.

So, for that I have made a custom menu with dialog.

dialog selection

dialog selection

The setup is based on .zlogin and .xinitrc.

The first one may vary between Linux distributions, and default shells. On Arch Linux with zsh, logging in executes .zlogin, startx executes .xinitrc.

         +-----------+  startx  +-----------+
login -->| .zlogin   |--------->| .xinitrc  |
         +-----------+          +-----------+

So, in .zlogin I have a menu of all the possible window managers, and even some applications.

# select window manager
if [[ -z ${DISPLAY} && ${XDG_VTNR} -le 2 && -z "${SSH_TTY}" ]] ; then
    export WM=$(dialog --backtitle "Login Manager" \
                       --nook --nocancel --no-tags \
                       --timeout 5 \
                       --menu "Select WM" 15 60 8 \
                   "spectrwm" "1: spectrwm" \
                   "hlwm"     "2: herbstluftwm" \
                   "bspwm"    "3: bspwm" \
                   "emacs"    "4: Emacs" \
                   "browser"  "5: Browser" \
                   "vbox"     "6: VirtualBox" \
                   "tmux"     "7: tmux" \
                   3>&1 1>&2 2>&3)
    clear
    exec startx
fi

By testing for ${XDG_VTNR} -le 2, this menu will run only on tty1 and tty2, and not from ssh.

In addition to the Window Managers, I also have a terminal with a tmux session, Emacs, a VirtualBox virtual machines selection menu, and Firefox.

Based on the selection, .xinitrc will run the equivalent WM or application.

case ${WM} in
    browser)
        exec firefox --kiosk --new-instance
        ;;
    emacs)
        xsetroot -solid black
        exec emacs -fs -mm
        ;;
    vbox)
        exec vboxmenu
        ;;
    tmux)
        xsetroot -solid black
        exec alacritty -d 382 80 --position 0 0 -e tmux
        ;;
    bspwm)
        exec bspwm
        ;;
    hlwm)
        exec herbstluftwm --locked
        ;;
    spectrwm|*)
        exec spectrwm
        ;;
esac

The menu will timeout in 5 seconds, and automatically login to the default option, which is spectrwm.

Important to note, that it is perfectly possible to have two different Window Managers or applications running concurrently on different ttys.