User Controlled X-Windows Session Chooser

A simple one.

I prefer to use the bog standard X.org xdm to log into X-Windows. However, I would also like to have the ability to choose a different windows manager on occasion. xdm doesn't provide a session manager. However, it does run the .xsession script in our home directory if it finds it.

We can leverage that:

.xsession
#!/usr/local/bin/bash
 
# run our profile and source it
. /home/ourusername/.bash_profile > /dev/null
 
# we could start some other progams here if we wished, just make sure to 
# start them in the background so we can continue on to make our window
# manager choice
#
# ie 
# xconsole &
 
# xmessage will return 101, 102, 1003 etc for the first second and third buttons
# unless we define a different value for a button's exit code
#
# use the default button if something isn't picked within five seconds
 
xmessage -name choosewm -center -timeout 5 -default xfce4 -buttons xfce4:10,lxde:11,mate:12 Select window manager
 
case $? in
   11)
      exec startlxde
       ;;
   12)
      exec mate-session
       ;;
   *)
      exec startxfce4
       ;;
esac