Adding a base directories class/module to the standard library

Hey folks,

During a recent discussion on Discord, I raised the idea of having an alternative to directories-rs in Crystal. @straight-shoota suggested that we discuss it further here and possibly include the newly added module in the standard library.

Benefits:

  • Consistent behavior across different operating systems. Configuration, cache, data, etc., would be accessed through a unified API without worrying about platform-specific nuances. This might benefit the compiler and Shards as well.
  • Promotion of best practices, whereas a Crystal developer might typically opt for a lazy solution, such as storing this data alongside the binary (which is not idiomatic on Linux and other operating systems).
  • It is relatively easy to implement, and almost no maintenance should be required.

Caveats:

  • Assuming this is going to be added, we would need to decide which directories are to be included. The bare minimum might be whatā€™s described in the XDG Base Directory Specification.

What are the thoughts?

12 Likes

We can probably take a lot of inspiration from the dirs-dev implementations (including directories-rs). Their authors seem to have figured out a practical API and behaviour.

Iā€™m a bit surprised though that the XDG_* environment variables seem to be only honored on Linux. I figure they should work on any operating system (if defined by the user).

Iā€™d even suggest to add this to the standard library. It provides functionality that could probably be useful for most CLI applications.

5 Likes

I find that odd too. Itā€™s a freedesktop specification part of X.org, and not tied to Linux in any way. Maybe they just donā€™t care or forgot about UNIX in general and *BSD in particular.

XDG_* has always felt like it just arrived too late to the party and has struggled for adoption.

Regardless, I think this is a great idea and would love to see it in stdlib.

1 Like

Thatā€™s very goodļ¼ any progress?

1 Like

Nowhere. Someone interested can start writing down a RFC to propose a Crystal API and how it each method would map to the different underlying system (UNIX, Windows, macOS) and maybe be fancy: iOS, Androidā€¦

4 Likes