#!/bin/bash

##################################################
## second_x_session.bash: version .00000002     ##
## Purpose:                                     ##
##   To choose xsessions from a menu            ##
##						##
## COPYRIGHT NOTICE:                            ##
##   Copyright   GPL                            ##
##   Created by: John Streeton Stile            ##
##   email:      john@stilen.com                ##
##################################################

#
# Incriment X display number
#
XDisplay="2"     # first display will be :1 

#
# May want to kill Xnest
#
echo "Shutting down previous Xnest instances"
sleep 2
pkill Xnest

################################################
# Must have Xnest installed
################################################
Xnest="/usr/X11R6/bin/Xnest"
if [ ! -e ${Xnest} ]; then
	echo "Please install the Xnest ( optional component of XFree86 )"
	exit
fi

################################################
#  Main Menu, options to see/change settings
#  Every function should return to this menu.
################################################

BOLD=$(tput smso)
NOBOLD=$(tput rmso)

while true
do
	clear
	cat <<- ENDMENU

                  ${BOLD}Second_X_session.bash (v..00000001)${NOBOLD}		                
                 
                      Choose second X session:
		      
   1) Aterm                                  6) Gnome
   2) Tabbed Window Manager (TWM)            7) After Step
   3) Window Maker                           8) KDE 
   4) Open Motif Window Manager              9) BlackBox
   5) F Virtual Window Manager (FVWM2)      10) Kill Xnest
                        O) other
                        X) Exit

	ENDMENU
	
	echo -e "Enter Choice: \c" 
	read choice
	case "$choice" 
	in  1 ) $Xnest :${XDisplay} -ac &
	        /usr/X11R6/bin/aterm -tr -sh 20 -fg green -fn font4 -trsb -sr -sl 10000 -display :${XDisplay} &
		;;
	    2 ) $Xnest :${XDisplay} -ac &
	        twm -display :${XDisplay}  
		pkill -f "$Xnest :${XDisplay}"
		;;
	    3 ) $Xnest :${XDisplay} -ac &
	        wmaker -display :${XDisplay}  
		pkill -f "$Xnest :${XDisplay}"
		;;
	    4 ) $Xnest :${XDisplay} -ac &
	        mwm -display :${XDisplay}  
		pkill -f "$Xnest :${XDisplay}"
		;;
	    5 ) $Xnest :${XDisplay} -ac &
	        fvwm2 -display :${XDisplay} 
		pkill -f "$Xnest :${XDisplay}"
		;;
	    6 ) $Xnest :${XDisplay} -ac &
	        gnome-session --display :${XDisplay} 
		pkill -f "$Xnest :${XDisplay}"
		;;
	    7 ) $Xnest :${XDisplay} -ac &
	        afterstep -d :${XDisplay}  
		pkill -f "$Xnest :${XDisplay}"
	        ;;
	    8 ) $Xnest :${XDisplay} -ac &
	        xterm -display :${XDisplay} -e 'kde'  
		pkill -f "$Xnest :${XDisplay}"
	        ;;
	    9 ) $Xnest :${XDisplay} -ac &
	        blackbox -display :${XDisplay}  
		pkill -f "$Xnest :${XDisplay}"
	        ;;
	    10) echo "Shutting down previous Xnest instances"
                sleep 2
                pkill Xnest
                ;;
	    [o,O] ) echo "Please enter full path to window manager: "
		    read Manager
		    ${Xnest} :${XDisplay} -ac &
	            xinit  ${Manager} -display :${XDisplay} 
		    pkill -f "$Xnest :${XDisplay}"
		    ;;
	    [x,X] ) echo "$choice"
		    exit 1
		    ;;
       esac
       # incriment the xdisplay not needed 
       let XDisplay=${XDisplay}+1

done
