[SOLVED] Choosing between multiple DEs/WMs to launch
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have both xfce and i3wm installed on my slackware machine. I'm know there are graphical "display managers" (not sure if that's the correct term) and "login managers" that will present the DEs or WMs that are installed and let you choose the one you'd like to launch. I would prefer to make the selection from the login shell, not graphically, by running startx. Everytime I want to switch between xfce and i3wm I have to comment out one of their entries in the .xinitrc file.
I'm wondering if there is a way to choose which one I'd like to launch with a bash script inside the .xinitrc file. I'm not familiar with bash but I'm sure I could learn what would be required for this task. I was thinking something along the lines of when startx or xinit is entered, the user would be prompted to enter a number, either 1 or 2. 1 corresponding to i3 and 2 corresponding to xfce. The following is pseudo code of course, but I thought it could work like:
Code:
prompt user for number
if ( number is 1 )
exec xfce
if ( number is 2 )
exec i3
To see if something like this would be possible I thought I would just try
Code:
echo 'HELLO XFCE'
into the .xinitrc file before the xfce section, but nothing printed to the screen. Maybe it displayed too fast for me to see it lol.
I was hoping that before I go and learn the bit of bash that's required for this task someone could tell me if I'm on the right path, or not? And, if not then tell me what I should be doing?
With just posix shell you could do something like this.
Code:
if [ $# -gt 0 ]; then
case "$1" in
xfce ) exec xfce ;;
i3 ) exec i3 ;;
* ) printf %s\\n "Unknown DE/wm '$1'"; exit 1 ;;
esac
else
exec xfce # this is the default choice without any arguments
fi
I would prefer to make the selection from the login shell, not graphically, by running startx.
If I may ask, why do you prefer that?
You can always select the runlevel when you boot; use 3 for a login shell and 4 for when you *know* that you will want a graphical environment and can then use kdm/xdm to select the environment. If you are in runlevel 3, you can nonetheless issue telinit 4 or (not tested) sudo telinit 4 to bring up kdm/xdm.
It's your system, of course, and you may certainly do things as you wish.
You didn't ask me, but I use startx too because I never really found the need for anything more. It works just fine and editing ~/.xinitrc is more than enough to start a minimal wm.
You didn't ask me, but I use startx too because I never really found the need for anything more. It works just fine and editing ~/.xinitrc is more than enough to start a minimal wm.
Well, normally I run XFCE. When I want to connect my Android phone to the computer to download photos, I've found out that I *really* need to be running KDE to do that; Thunar times out every time.
I use kdm to log in every time; it's easy to log out of XFCE, select KDE, and log into that. When I'm done, reverse the process.
#!/bin/sh
# This script sets the X session started with the startx command or
# with a display manager, unless the session be set from the display
# manager's greeter.
# Tested with xdm, lightdm, lxdm, kdm and gdm2
# Known issue: with some sessions xdm respawns
# The script user-xsession.py needs accountsservice and is shipped in
# the accountsservice package in Slint.
# Didier Spaier <didier~at~slint~dot~fr> 25 November 2017
if [ $(id -u) -eq 0 ]; then
echo "Running a graphical session as root is not allowed."
exit
fi
liste="$(ls /usr/share/xsessions/|sed s/.desktop//)"
listew=". $liste ."
usage() {
echo "Usage: $0 <desktop session>"
echo "Available desktop sessions:"
echo "$liste"
printf "The session is currently set for $USER to "
user_xsession.py --user-name $USER get
exit
}
[ $# -ne 1 ] && usage
if [ "$(echo $1|tr [:lower:] [:upper:])" = "LXDE" ]; then
thissession="LXDE"
else
thissession=$(echo $1|tr [:upper:] [:lower:])
fi
if [ "$(echo $listew|grep " $thissession ")" = "" ]; then
echo "\"$1\" not found among the available sessions"
echo "$liste"
printf "The current session is "
user_xsession.py --user-name $USER get
exit
fi
user_xsession.py --user-name $USER set $thissession
# This is for xdm
case $thissession in
kde-plasma) session=/usr/bin/startkde;;
kde-plasma-safe) session="/usr/bin/startkde --failsafe";;
LXDE) session=/usr/bin/lxsession;;
gnome) session=/usr/bin/gnome-session;;
xfce) session=/usr/bin/startxfce4;;
icewm) session=/usr/bin/icewm-session;;
mate) session=/usr/bin/mate-session;;
wmaker) session=/usr/bin/startwmaker;;
e16) session=/usr/share/e16/misc/starte16;;
enlightenment) session=/usr/bin/enlightenment_start;;
blackbox) session=/usr/bin/startblackbox;;
fluxbox) session=/usr/bin/startfluxbox;;
twm) session=/usr/bin/starttwm;;
awesome) session=/usr/bin/awesome;;
esac
echo $session > $HOME/.xsession
# This is for lxdm and gdm2.
echo '[Desktop]' > $HOME/.dmrc
echo "Session=$thissession" >> $HOME/.dmrc
xsession=$thissession
[ "$xsession" = "LXDE" ] && xsession=lxde
[ "$xsession" = "kde-plasma" ] && xsession=kde
[ "$xsession" = "kde-plasma-safe" ] && xsession=kde
# This is mostly for startx , borrowed from xwmconfig.
if [ -r /etc/X11/xinit/xinitrc.$xsession ]; then
if [ -r $HOME/.xinitrc ]; then
rm -f $HOME/.xinitrc-backup
mv $HOME/.xinitrc $HOME/.xinitrc-backup
fi
cat /etc/X11/xinit/xinitrc.$xsession > $HOME/.xinitrc
fi
echo "A default session $thissession has been set for ${USER}."
@Skaendo @orbea @Didier Spaier - Thanks for the code. I'm learning my first programming language right now, which has allowed me to follow the logic of these scripts quite a bit, but I will have to study bash to understand the finer points.
@montagdude @mralk3 - Thanks for info about xwmconfig. I do have dmps settings in .xinitrc for when i3 is launched that would be wiped out if I were to switch to a different de/wm.
@Richard Cranium - Nice to hear from you again. Well, to be honest besides the different run levels I wasn't aware of the other options you mentioned, including being able to select different run levels upon booting (I'll look into that). Since I started using Slackware I've just left it at run level 3 and used startx, I was only using one wm at the time, though. Now that I have two, I basically just thought of a solution building on what I already knew; startx. Since all that was in my .xinitrc file to start i3 was one line: exec i3, I thought I would try to see if I could add a script to that file with a simple if-else construct and may or may not prompt the user for input. So, instead of issuing "startx" I would just type "startx i3" or "startx xfce", or after issuing "startx" I would be prompted to make a selection, which if worked, wouldn't be much trouble at all. Also, I thought it would be cool
Thanks again for the support. It's much appreciated.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.