Reputation: 425
I'm trying to figure out a good way to use one emacs config for different systems. I'm using emacs on windows inside WSL for work, but also on my linux machine at home.
The different systems have different requirements, for example at home, I use the exwm
package as my window manager. When using emacs though WSL however, I don't need that package, there are other cases, this is just an example.
I don't want to split my config into two seperate repos (one for linux, one for wsl) because there is a fair amount of code that would get duplicated and hence needed to be updated twice if something changes.
So far, I've come up with something like this:
; Determine which OS we are on.
(if (string-match "Microsoft" (car (split-string (shell-command-to-string "uname -r"))))
(setq ENV "wsl")
(setq ENV "linux"))
I can then do something like this:
(if (equal ENV "linux")
(setq doom-font (font-spec :family "Cozette" :size 12))
(setq doom-font (font-spec :family "Inconsolata" :size 18)))
However, I don't know if this is a good way or not. I'd appreciate any input on the subject matter.
Upvotes: 1
Views: 789
Reputation: 17422
There's a number of different ways to achieve what you're after, the "right way" is mostly a matter of preference.
For instance, you could split your configuration up into three files:
File #1 would be your standard init file at the end of which you could insert some code to load either file #2 or #3 depending on what platform you're on:
(if (string-match-p "microsoft" operating-system-release)
(load-file path-to-wsl-config-file)
(load-file path-to-linux-config-file)
Upvotes: 1