Computer-specific i3 Config


Here's a way to config i3 specific to a computer within a single i3 config file.

This is a version of this article's solution with a few more basics for a n00b like me.

Set a Hostname

First, we must identify our particular computer. We'll do this by setting a hostname. I'll call my host rexkwando:

hostnamectl set-hostname rexkwando

Static Config

Usually, if I was setting my config in i3, I might set a font face and size like this, the font being "BlexMono Nerd Font Mono" and the size being "10":

font pango:BlexMono Nerd Font Mono 10

Host-specific Config

But now I'm going to set that font family and size definition in a file that understands hostname conditionals, and that's ~/.Xresources:

*i3font: pango:BlexMono Nerd Font Mono 10
#ifdef SRVR_rexkwando
  *i3font: pango:BlexMono Nerd Font Mono 12
#endif

This creates a variable named i3font. The standard font size is "10". But inside the conditional, which checks for a hostname of rexkwando, the font size will be set to "12".

Using .Xresources Config in i3

And it turns out that i3 can load this i3 variable using set_from_resource:

set_from_resource $i3font i3wm.i3font pango:BlexMono Nerd Font Mono 10font $i3font
font $i3font
  • set_from_resource loads the value from X and a fallback if it's not there and sets it in $i3font.
  • font sets the font for i3 from that value.

Reload to See It

Once you have hostname set, .Xresources and i3/config, you need to reload them.

To reload ~/.Xresources, go to your terminal and type:

xrdb ~/.Xresources

To reload i3, use your key shortcut, for me:

bindsym $mod+Shift+c reload

Or in terminal:

i3-msg reload

Now on rexkwando, you'll see a larger font. Just break the wrist and walk away.