Page 1 of 1
wm-swap
Posted: Sat Mar 05, 2016 1:11 am
by elixir
Just a little tool I wrote to easily change your .xinitrc config so X will jump into a new window manager when restarted. Thought it would be useful to some.
Usage:
Code:
Code: Select all
#/bin/bash
#
# This is a tool that will edit you .xinitrc file to comment
# your current wm, and uncomment your desired wm.
#
if [ -z $1 ]; then
echo "Usage: wm-swap [window manager]"
exit 1
else
WM="$1"
fi
xinit="/home/$USER/.xinitrc"
if [ -f /home/$USER/$xinit.temp ]; then
rm $xinit.temp
fi
found=0
while read line; do
if [[ $line =~ ^exec ]]; then
echo $line | sed 's/^/#/' >> $xinit.temp
elif [[ $line =~ $WM ]]; then
echo $line | sed 's/#//' >> $xinit.temp
found=1
else
echo $line >> $xinit.temp
fi
done < $xinit
if [ $found == 0 ]; then
echo "exec $WM" >> $xinit.temp
fi
cp $xinit.temp $xinit
rm $xinit.temp
## optional
# pkill x
exit 0
Re: wm-swap
Posted: Sat Mar 05, 2016 2:43 am
by dkeg
kudos on the idea. I had something, idea wise for swapping current wall. Anyway, this is what I do.
Here's my
.xinitrc
Re: wm-swap
Posted: Sat Mar 05, 2016 2:48 am
by elixir
^ Wow, that is a genius idea. Thank you for sharing.
I was hoping to implement something that could actually reload the X server for you, but I could not find a good way to do it. Since most users would run this in a virtual terminal, it would get as far as killing the X server which would then kill the script itself.
Re: wm-swap
Posted: Sat Mar 05, 2016 4:40 am
by machinebacon
I think the optional line should be:
To reload the Xserver, the only method I can think of is automatically starting it via ~/.bash_profile (or ~/.profile) on a selected TTY.
There is another way of doing what your script can do, but it is extremely Debian-ish:
- keep "exec x-window-manager" as magic line in ~/.xinitrc
- on Debian systems, use the interactive mode of 'update-alternatives' to select the window manager
- on non-Debian systems, link /usr/bin/x-window-manager to the window manager of choice
This would not tinker with ~/.xinitrc, and not create temp files.
Re: wm-swap
Posted: Sat Mar 05, 2016 8:35 am
by Snap
Plenty of smart ideas here. Great job, folks. Thanks for sharing.
Re: wm-swap
Posted: Sat Mar 05, 2016 4:46 pm
by Snap
@ dkeg:
What's wew in your .xinitrc? And xwait? Is it a script? I don't see it described in the xinit or startx man pages. Does it belong to any other xserver bit? Never heard of those two before.
Re: wm-swap
Posted: Sat Mar 05, 2016 4:55 pm
by machinebacon
Re: wm-swap
Posted: Sun Mar 06, 2016 5:24 am
by rhowaldt
^ what!? google??? that is a revolutionary approach! ;)
Re: wm-swap
Posted: Sun Mar 06, 2016 4:15 pm
by pidsley
If you don't need conditionals, you can just use this last line in .xinitrc:
Then call xinit with the name of the wm you want to start.
If you want to use a fancy dialog to pick the wm, try the pick-wm script from cream (this requires the "exec $1" mod to .xinitrc):
https://github.com/linuxbbq/toolbox/blob/master/pick-wm
If I wanted to switch window managers from inside X, I'd probably write the name of the new window manager to a temp file, pkill X, and then "xinit $(<tmpfile)".
Re: wm-swap
Posted: Sun Mar 06, 2016 4:55 pm
by machinebacon
addendum to the last idea of pidsley:
if the magic process is not a window manager, but something else (a fake process like a loop), the WM could even by switched on the fly - I think - using a pick-wm script that does not "exec <wm>" but simply starts "<wm> &". Though I am not sure how often people switch their WMs a day.
Re: wm-swap
Posted: Sun Mar 06, 2016 5:11 pm
by pidsley
machinebacon wrote:Though I am not sure how often people switch their WMs a day.
Exactly. I just have a list of commented "exec" lines and an alias that opens my .xinitrc file. If I want to change wms I edit the file, change the comments, and restart X. I only do this when I need to test something in another wm, so a script seems like overkill. But that's just my opinion, worth exactly what you paid for it.
Re: wm-swap
Posted: Mon Mar 07, 2016 11:01 am
by Snap
^ That's how my .xinitrc looks like too. Anyway these WM switching methods are useful and good to know when tweaking a new WM. Switching back and forth to check changes and differences.
Thanks for all the info, guys.