macos Mac OS X 上 XDG_CONFIG_HOME 和 XDG_DATA_HOME 的等价物?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3373948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Equivalents of XDG_CONFIG_HOME and XDG_DATA_HOME on Mac OS X?
提问by LeafStorm
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, downloaded plugins) in XDG_DATA_HOME
. On Windows, it will use APPDATA
for both (unless someone has a better idea). However, what would be the proper thing to do on Mac OS X?
我打算开发一个跨平台的脚本。在 Linux 和其他操作系统上,它会将配置存储XDG_CONFIG_HOME
在XDG_DATA_HOME
. 在 Windows 上,它将APPDATA
用于两者(除非有人有更好的主意)。但是,在 Mac OS X 上应该做什么?
On my first glance through a handy Macbook's ~/Library
directory, I saw Preferences
and Application Support
folders. I was originally planning to use those, but Preferences
seems to just contain plists with reverse domain names like com.apple.foo.bar.baz.plist
, and every folder in Application Support
corresponds to a bundle in /Applications
, so I'm not sure how well the system would react to files that don't match its standards. Storing them directly in ~/Library
might be an option, but I don't want to pollute it with a stray myscript.conf
file if there's a better place for it.
通过一个方便的MacBook的我第一眼~/Library
目录,我看到了Preferences
和Application Support
文件夹。我最初计划使用这些,但Preferences
似乎只包含具有反向域名的 plist,例如com.apple.foo.bar.baz.plist
,并且中的每个文件夹都Application Support
对应于 中的一个包/Applications
,因此我不确定系统对与其不匹配的文件的反应如何标准。将它们直接存储在其中~/Library
可能是一种选择,但myscript.conf
如果有更好的地方,我不想用杂散文件污染它。
Where should I store these files? (And please don't say just ~/.myscript
. I know it's the Unix tradition, but it annoys me to see random dotfiles in the home directory.)
我应该在哪里存储这些文件?(请不要只说~/.myscript
。我知道这是 Unix 的传统,但是在主目录中看到随机的点文件让我很恼火。)
采纳答案by Yuji
I would use ~/Library/Application Support/script_name/
. The subdirectories inside Application Support
are used conventionally by various apps, including Apple's own softwares. But it's not enforced by the OS and not tied to apps inside /Applications
. So you're perfectly free to create your own directory in it.
我会使用~/Library/Application Support/script_name/
. 里面的子目录Application Support
通常被各种应用程序使用,包括苹果自己的软件。但它不是由操作系统强制执行的,也不受内部应用程序的约束/Applications
。因此,您可以完全自由地在其中创建自己的目录。
For the directory structure of OS X in general, see this Apple document.
有关 OS X 的一般目录结构,请参阅此 Apple 文档。
回答by jla
Comparing Apple's documentation for the various paths to the XDG Base Directory specifications approximates to the following locations:
比较 Apple 的文档以了解 XDG 基本目录规范的各种路径,大致位于以下位置:
XDG_CONFIG_HOME
??~/Library/Preferences/
XDG_DATA_HOME
??~/Library/
XDG_CACHE_HOME
??~/Library/Caches/
XDG_CONFIG_HOME
??~/Library/Preferences/
XDG_DATA_HOME
??~/Library/
XDG_CACHE_HOME
??~/Library/Caches/
Mapping XDG Base Directory Specification locations for "My App" on Mac OS X could look like this:
在 Mac OS X 上为“我的应用程序”映射 XDG 基本目录规范位置可能如下所示:
XDG_CONFIG_HOME
??~/Library/Preferences/name.often.with.domain.myapp.plist
XDG_DATA_HOME
??~/Library/My App/
XDG_CACHE_HOME
??~/Library/Caches/My App/
XDG_CONFIG_HOME
??~/Library/Preferences/name.often.with.domain.myapp.plist
XDG_DATA_HOME
??~/Library/My App/
XDG_CACHE_HOME
??~/Library/Caches/My App/
These mappings seem pretty reasonable but they aren't exact. Some kinds of cache or data may be appropriate for ~/Library/Application Support/My App
, and other may be best in the temp locations or the App bundle. All of it is by convention and the same reasons for using the best XDG_
locations apply to using the best locations on the Mac OS X system.
这些映射看起来很合理,但并不准确。某些类型的缓存或数据可能适用于~/Library/Application Support/My App
,而其他类型的缓存或数据可能最适合临时位置或应用程序包。所有这些都是按照惯例,使用最佳XDG_
位置的相同原因也适用于在 Mac OS X 系统上使用最佳位置。
Your annoyance at ~/.myscript
is in line with Apple's guidelines: "Don't pollute user space".
你的烦恼~/.myscript
符合苹果的指导方针:“不要污染用户空间”。
References:
参考:
回答by Franklin Yu
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.
我同意OJFord 的评论:如果您正在编写脚本(我认为这适用于所有仅 CLI 的应用程序),只需遵循 XDG Base Directory 会更好。
Rationales:
理由:
- Names in
XDG_CONFIG_HOME
are typically small-case bare-names likegit
; the ones in~/Library/Preferences/
are typically scoped with reversed domain names likecom.apple.foo-bar
, or first-letter-capital space-delimited names likeFoo Bar
. - 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. ~/Library/Preferences/
is full of.plist
s. No cross-platform script that I know is using property lists.- Users may want to sync cross-platform configuration and macOS-only one separately.
- 中的名称
XDG_CONFIG_HOME
通常是小写的裸名,例如git
; 中的那些~/Library/Preferences/
通常以反向域名为范围,例如com.apple.foo-bar
,或首字母大写空格分隔的名称,例如Foo Bar
。 - GUI 应用程序在放置在
/Applications
. 你没有把你的脚本放在/Applications
; 您将它们放在UNIX 特定的目录中。最好保持一致。 ~/Library/Preferences/
充满了.plist
s。据我所知,没有跨平台脚本使用属性列表。- 用户可能希望分别同步跨平台配置和仅限 macOS 的配置。
For example, Git places their config file in XDG_CONFIG_HOME/git/config
, not in ~/Library/Preferences/Git/config
. Makes sense to me.
例如,Git 将他们的配置文件XDG_CONFIG_HOME/git/config
放在~/Library/Preferences/Git/config
. 我感觉合理。
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 Machineby 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:
我只针对配置文件 ( $XDG_CONFIG_HOME
) 和数据文件 ( $XDG_DATA_HOME
)提出了这一点;对于缓存文件,它变得微妙。根据How-To Geek,默认情况下~/Library/Caches
从Time Machine 中排除目录。我不关心缓存文件夹,因为无论如何我都不备份目录;但是对于那些关心的人,我建议他们链接~/.cache
到默认缓存文件夹中的某个位置,例如:
cd ~; mv .cache ~/Library/Caches/XDG-cache; ln -s ~/Library/Caches/XDG-cache .cache