I have been looking for an OCaml library with a robust implementation that provides a uniform, cross-platform interface for XDG Directories / Known Folders (Windows) / Standard Directories (macOS), and I believe bos is one of the best places to implement these functions. More specifically, I need these features for my development:
Basic path expansion for the home directory. For example, I hope there would be a function expanding both $HOME/blah and ~/blah to /home/user/blah on Linux. This is essentially #77.
Reasonable default directories for (at least) data (XDG_DATA_HOME), configurations (XDG_CONFIG_HOME), and cache (XDG_CACHE_HOME) on major platforms.
I have checked other OCaml libraries and I feel a robust implementation would inevitably reimplement many functions in bos. The most non-trivial part is perhaps the OS detection (usually done by uname -s, but could also be done by the uname system call) and some other system calls to get known folders on Windows. As a bonus, I also hope the implementation has the following features, though I personally do not need them:
Understand that on Plan 9, the environment variable HOME should be home and various directories are placed differently.
Support other base directories, user directories, font directories, etc.
Parse $XDG_CONFIG_HOME/user-dirs.dirs for user directories, if we wish to support them.
Perhaps provide an option for macOS to mimic the Linux convention for easier Linux/macOS synchronization? (I'm not sure what would be the best practice, especially for command-line tools.)
One of the most robust and feature-rich libraries I found is adrg/xdg for Go. The only major missing piece in that library is the parsing of $XDG_CONFIG_HOME/user-dirs.dirs for user directories.
I am happy to make a PR containing a half-baked implementation that would address my need, leaving a truly robust implementation to others. My plan is to add OS.Path.expand_home, OS.Dir.cache, OS.Dir.data, and OS.Dir.home (as an alias of OS.Dir.user), and then make the existing OS.Dir.user a bit more cross-platform. I'd love to hear some feedback before putting my plan into action.
I have been looking for an OCaml library with a robust implementation that provides a uniform, cross-platform interface for XDG Directories / Known Folders (Windows) / Standard Directories (macOS), and I believe
bos
is one of the best places to implement these functions. More specifically, I need these features for my development:$HOME/blah
and~/blah
to/home/user/blah
on Linux. This is essentially #77.XDG_DATA_HOME
), configurations (XDG_CONFIG_HOME
), and cache (XDG_CACHE_HOME
) on major platforms.I have checked other OCaml libraries and I feel a robust implementation would inevitably reimplement many functions in
bos
. The most non-trivial part is perhaps the OS detection (usually done byuname -s
, but could also be done by theuname
system call) and some other system calls to get known folders on Windows. As a bonus, I also hope the implementation has the following features, though I personally do not need them:HOME
should behome
and various directories are placed differently.$XDG_CONFIG_HOME/user-dirs.dirs
for user directories, if we wish to support them.One of the most robust and feature-rich libraries I found is adrg/xdg for Go. The only major missing piece in that library is the parsing of
$XDG_CONFIG_HOME/user-dirs.dirs
for user directories.I am happy to make a PR containing a half-baked implementation that would address my need, leaving a truly robust implementation to others. My plan is to add
OS.Path.expand_home
,OS.Dir.cache
,OS.Dir.data
, andOS.Dir.home
(as an alias ofOS.Dir.user
), and then make the existingOS.Dir.user
a bit more cross-platform. I'd love to hear some feedback before putting my plan into action.