Switching DE/WM depending on TTYs

Sometimes I like to switch from a session to another just for practice and improve my configs, but I don’t
like display or login managers, I prefer using startx.
Before I search how to switch from depending on TTYs, the last section of my ~/.xinitrc looked as follows:

session=${1:-bspwm}

    case $session in
        bspwm             ) exec bspwm;;
        i3|i3wm           ) exec i3;;
        # No known session, try to run it as command
        *                 ) exec $1;;
    esac

So to run another session than the default I had to type:

startx ~/.xinitrc i3

Now i connect automatically after entering my username and password according to the TTY with this code instead: tty1=bspwm tty2=i3 tty3=some other WM/DE

# refers to ~/.zlogin
case $(tty | cut -b9-) in
	(1) exec bspwm;;
	(2) exec i3;;
	(3) some other WM/DE;;
esac

To do so I’ve created a ~/.zlogin and made it executable chmod +x ~/.zlogin (zsh users)

#!/bin/sh
#~/.zlogin

# Auto startx depending on the tty
if [[ -z $DISPLAY ]] && (( $EUID != 0 )) {
    [[ ${TTY/tty} != $TTY ]] && (( ${TTY:8:1} <= 3 )) &&
        startx 1>~/.xsession-errors 2>&1 &
}

Give it a try :upside_down_face: :wink:

4 Likes

Top work again @archus .

Thx for sharing here.

1 Like

This was something @natemaia showed me many moons ago. Thanks you for sharing and reminding me.

1 Like

Nice work @Archus :+1:

Note that desktop environments such as GNOME & Plasma will need to be started from scripts:

https://bbs.archlinux.org/viewtopic.php?pid=1887508#p1887508

2 Likes