HOWTO: choose a window manager at random

Forum rules
Share your brain ;)
pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

HOWTO: choose a window manager at random

Unread post by pidsley » Mon Jul 15, 2013 1:26 am

I wrote a silly window manager choosing script. It displays a dialog box that lets you choose a window manager from a list, and the last entry is "random" -- if you select "random" the script will choose one from the list for you.

The script assumes you are using "startx" and .xinitrc to start your window manager. Modify your .xinitrc so that the last two lines look like this (the xmessage call puts up a little box to tell you which WM you are using; you can delete this if you really want to be surprised):

Code: Select all

xmessage -timeout 5 -center "you are running"$1
exec $1
Put the script somewhere in your path, and call it whatever you like. Make sure it is executable.

Code: Select all

#!/bin/bash

# the list of window managers can be read from a file, one line at a time
#alist=(`cat wmlist`)

# or set the list here inside the script. either way the last entry should always be "random"
alist=( ratpoison cwm twm sithwm fluxbox openbox blackbox ctwm alopex monsterwm random )

let num=${#alist[*]}-1     # number of items in the array (minus one to account for zero index)
tmpfile=`mktemp`            # make a temp file for dialog return value

# make a list in menu format, with a number first, then the name
for i in `seq 0 $num`; do
    blist[i]=`echo $i ${alist[i]}`
done

# display the list in a dialog, save the return value (the index number) in the tmpfile
dialog --no-tags --menu 'choose a window manager' 50 50 10 ${blist[*]} 2>$tmpfile
chosen=$(<$tmpfile)     # get the index from the tmpfile

if [ $chosen -eq $num ]; then   # last choice is always "random"
    let RANGE=$num              # set range to zero to number of elements minus one
    chosen=$RANDOM              # pick a random integer
    let chosen%=$RANGE          # use modulo operator to make it within range
fi

rm $tmpfile     # delete the temp file

# index into the WM array to get the name of the WM, and start it
xinit ${alist[$chosen]}
If you would like to read the window-manager names from a file, create a file called "wmlist" and put the list in the file, one line per WM, with "random" as the last line, then uncomment the `cat wmlist` call and comment out the line where the array is set inside the script. Otherwise, just modify the list inside the script. The script does not check to see if you have a window manager installed, so make sure the list is correct.

Then, instead of calling "startx" just call the script from the console after you log in.

Post Reply