Platform specific settings


#1

Can someone please explain how I can set platform specific settings?

For example I run on OSX and Windows, and I would like to configure the ‘atom-terminal’ package.

I want to set it up so in Windows it runs PowerShell and on OSX iTerm.app (both are not the defaults for the package).

How do I do this? It looked like maybe I could have “*”, “platform-darwin” and “platform-win32” as roots in my config.cson but it doesn’t seem to work…


#2

This is not supported in Atom itself. Platform specific settings needs to be provided as a feature in packages for the time being.


#3

You can do something like

if document.body.classList.contains 'platform-darwin'
  atom.config.set 'core.x', y
else if document.body.classList.contains 'platform-win32'
  atom.config.set 'core.x', z

in your init.coffee, not as nice as what you describe, but it’s something :wink:


#4

Yeah that will work. Thanks :smile:

It’s just super gross that each time I load atom my config will change. Which is even more messed up when I change platforms…


#5

Here’s another idea: you can make a darwin and a win32 entry in your config.cson. Then in init.coffee:

if platform = document.body.className.match(/platform-(darwin|win32|linux)/)?[1]
  config = fs.readFileSync atom.config.getUserConfigPath()
  config = JSON.parse config.toString()
  if config[platform]?
    for own key, value of config[platform]
      atom.config.set key, value

#6

Or you might get even fancier, and have platform-scoped, grammar-scoped configs:

if platform = document.body.className.match(/platform-(darwin|win32|linux)/)?[1]
  path = require 'path'
  CSON = require path.join atom.getLoadSettings().resourcePath, '/node_modules/season'
  config = CSON.readFileSync atom.config.getUserConfigPath()
  if config[platform]?
    for own scopeSelector, scopeConfig of config[platform]
      for own namespace, namespaceConfig of scopeConfig
        for own key, value of namespaceConfig
          atom.config.set "#{namespace}.#{key}", value, scopeSelector

Then you can have this in your config.cson:

'*':
  'editor':
    'softWrap': true # enable softWrap
'source.python':
  'editor':
    'softWrap': false # except in python files
'darwin':
  '*':
    'editor':
      'softWrap': false # disable softWrap on mac
  'source.python':
    'editor':
      'softWrap': true # except in python files :)

I haven’t tested any of this code though so maybe you need to fix some things

EDIT Ok so of course you need a .cson parser if you want to parse config.cson… updated the code (you should copy it all, the old code had a bug that wiped your config.cson)


#7

Thanks! Seems to work well.


#8

Very cool, @olmokramer. Thanks for that. If I understand, this will take whatever is in the platform dependent sections and add them to the default section. I have settings for Windows that need to preempt the defaults. It looks like I have to add the default settings to the other platforms in order for them to take effect properly? I should mention that I share the same config files between platforms (as described in my and others’ StackOverflow answers.

Atom doesn’t retain the config file in memory? If so, then only the memory representation of the “active” settings need be modified (and the file, not touched)


#9

Atom reads from the file constantly. If you change the content of config.cson, it will be reflected in Atom’s behavior.