Different configurations for different operating systems?


#1

I’d like to load different configurations on different operating systems. I mean, I want to copy my {config, keymap, snippets}.json, init.js, and packages (including themes) to different operating systems, and Atom will behave differently. For example, on OS X, I want Atom to load unity-ui and atom-dark-syntax; but on GNU/Linux, I want Atom to load seti-ui and seti-syntax. I can use system-type in Emacs:

(if (eq system-type 'darwin)
  ; something for OS X if true
  ; optional something if not
)

But I don’t know how to do this in Atom. After searching, I only found the process.platform API in Node.js, but I don’t know how to apply it to the .json/.cson files. Can anyone point me in the right direction?


#2

I think your init.js can test the system and do different things, but for *.json and *.cson this won’t do because these files don’t contain logic, they are just data.

Hm.

The easiest might be to do it outside Atom: have files config-mac.json and config-linux.json, and add a “build” script that symlinks the correct one on each host.

Another option might be that perhaps Atom has an API to tweak the same things that config.json can tweak, and thus you put the unchanging parts into config.json and then add the varying portions via init.js or init.coffee.


#3

For all the config files that uses scopes (keymap, snippets, etc.) I believe you should be able to scope everything using the platform class added on the body:

'.platform-darwin atom-workspace': 
  'cmd-f': 'my-search'

'.platform-win32 atom-workspace': 
  'ctrl-f': 'my-search'

There might be an issue with snippets as the scope is probably evaluated within the editor shadow DOM.


#4

Check out https://github.com/szwacz/electron-boilerplate. There is some platform specific helper functions available.