I run multiple X sessions, my primary WM ratpoison on TTY7, then a development ratpoison on TTY8. Since I like to boot different configuration files per which RP enviroment I want I wrote this little script to allow me to specify what configuration I want when calling startx. The script uses the directory ~/.xinit as the place holder for all configurations following the naming convention of xinit0, xinit1, xinitN. I suggest you backup your original ~/.xinitrc before running this.
I plan to expand on this script and add some features sometime(some rainy day) but for now it suites my fancy so I shall leave it be. I would love to hear any and all feedback on it.
If the desired screen isnt specified on the command line the script will attempt to detect if a session of X is allready running, if so it will increment the screen number by one. if not it will default to 0.
Code:
#!/bin/bash
# Synopsis: Small wrapper for startx to allow for easy command line specification
# of startx options
# Author: thims (root DOT packet AT gmail DOT com)
# Date: 20090316
# Comments:
#
#
# Configuration file directory tree and naming convention
# By default the configuration directory is set to ~/.xinit but
# this can be changed in the "$confdir" variable.
# $ tree ~/.xinit
#.xinit
# |-- xinit0
# |-- xinit1
# |-- xinit2
# |-- xinit3
# `-- ...
# ToDo:
# - Add the ability to detect a custom naming convention from the name of "$defaultConf"
# - Add the ability to check and make a backup of original .xinitrc file?
defaultConf="xinit0"
confdir="$HOME/.xinit"
while [ $# -gt 0 ]
do
case "$1" in
"-h"|"--help")
;;
"-s"|"--screen")
if [ -z "$2" ] ;then
echo "Error: -s requires exactly one argument, 0 provided"
exit 1
else
Xsessions=$(ls /tmp/.X11-unix/ | grep "$2" >/dev/null ;echo $? )
if [ $Xsessions == 0 ] ;then
echo "Error: that X screen slot is allready filled, try another"
else
screen="$2"
fi
fi
;;
"-c"|"--config")
if [ -z "$2" ] ;then
echo "Error: -c requires exactly one argument, 0 provided"
elif [ ! -e "$confdir/xinit$2" ] ;then
echo "Error: $confdir/xinit$2 does not exist, please create it or specify another config"
else
ln -snf "$confdir/xinit$2" "$HOME/.xinitrc"
conf=true
fi
;;
esac
shift
done
if [ -z $screen ] ;then
if [ $(ls /tmp/.X11-unix/ | wc -l) -lt 1 ] ;then
screen=0
else
screen=$(ls /tmp/.X11-unix/ | tail -1 | sed 's/[a-zA-Z=]//g')
screen=$((screen + 1))
fi
fi
if [ -z $conf ] ;then
ln -sf "$confdir/$defaultConf" "$HOME/.xinitrc"
fi
startx :$screen