Equivalents of XDG_CONFIG_HOME and XDG_DATA_HOME on Mac OS X?

前端 未结 3 1030
花落未央
花落未央 2021-01-30 22:46

I am planning to develop a cross-platform script. On Linux and other operating systems, it will store configuration in XDG_CONFIG_HOME and data files (specifically,

3条回答
  •  星月不相逢
    2021-01-30 23:32

    I agree with OJFord's comment: if you are writing a script (I think this applies to all CLI-only application), simply follow the XDG Base Directory would be better.

    Rationales:

    1. Names in XDG_CONFIG_HOME are typically small-case bare-names like git; the ones in ~/Library/Preferences/ are typically scoped with reversed domain names like com.apple.foo-bar, or first-letter-capital space-delimited names like Foo Bar.
    2. GUI applications have been following macOS conventions when they are placed in /Applications. You don't place your script in /Applications; you place them in UNIX-specific directorys. Better to be consistent.
    3. ~/Library/Preferences/ is full of .plists. No cross-platform script that I know is using property lists.
    4. Users may want to sync cross-platform configuration and macOS-only one separately.

    For example, Git places their config file in XDG_CONFIG_HOME/git/config, not in ~/Library/Preferences/Git/config. Makes sense to me.

    note

    I made the point only for configuration files ($XDG_CONFIG_HOME) and data files ($XDG_DATA_HOME); for cache files it gets subtle. According to How-To Geek, ~/Library/Caches directory is excluded from Time Machine by default. I don’t care about cache folder since I back up neither directories anyway; but for ones who care, I recommend them to link ~/.cache to somewhere in the default cache folder, such as:

    cd ~; mv .cache ~/Library/Caches/XDG-cache; ln -s ~/Library/Caches/XDG-cache .cache
    

提交回复
热议问题