Setting environment variables before i3wm starts

After poring through pages of documentation to figure out how to use systemd unit files to set environment variables, I suddenly realized that none of this was necessary. I’ve figured out a much simpler (and cleverer) way to solve this problem: using symbolic links.

Here is my solution:

#Inside ~/.screenlayout/monitor.sh

xrandr --output ..... #xrandr calls generated by arandr

output=$(xrandr --listactivemonitors)
number_of_monitors=$(echo $output | cut -d " " -f 2)
name_of_symlink="/home/anthony93/.config/i3/additional_monitor_config"
reset_symlink(){
    if [[ -L $1 ]]
    then
        rm $1
    fi
}

reset_symlink $name_of_symlink

if [[ "$numer_of_monitors" == "2" ]]
then
    ln -s "/home/anthony93/.config/i3/config_dual_monitor.conf" $name_of_symlink
elif [[ "$number_of_monitors" == "3" ]]
then
    ln -s "/home/anthony93/.config/i3/config_three_monitor.conf" $name_of_symlink
else 
    ln -s "/home/anthony93/.config/i3/config_single_monitor.conf" $name_of_symlink
fi

Now, all I have to do is organize my display configurations in three separate files ( ~/.config/i3/config_single_monitor.conf, ~/.config/i3/config_dual_monitor.conf, and ~/.config/i3/config_three_monitor.conf), and then point a symbolic link to the right file based on the output obtained in monitor.sh

The symbolic link would then be included inside i3’s main config file

include ~/.config/i3/additional_monitor_setup