elvish
elvish copied to clipboard
Where should packages store their data
I needed to store some state in my elvish-gitstatus package and I used the following place:
~/.elvish/package-data/gitstatus
This is super low-priority, but I was wondering: Does anyone have a better idea? Is there already a common place where others store their state?
$XDG_DATA_HOME or .local/share
I don't think there's an accepted convention, but storing it under ~/.elvish/ sounds reasonable. @SolitudeSF's suggestions make sense too. My aliases module stores the alias definitions under ~/.elvish/aliases/.
One reason I didn't store it outside of .elvish is the thought that this keeps everything related to Elvish in one place, so cleanup is more straight-forward.
I agree with that, I like having the whole config coalesced under a single directory. I am not much of a fan of XDG :)
I just noticed you are another Swiss Elvish user 🇨🇭👍
The Swiss do like high quality tools 😉
As others said, there isn't any guidance at the moment yet.
This should take into account the proposal to switch to using the XDG specification, issue #383. Since the data discussed in this issue is inherently per-system it should be stored someplace under ~/.local/share/elvish if the project adopts the XDG spec.
FWIW, I just started seeing this warning after upgrading elvish to the HEAD version a few minutes ago:
Warning: ~/.elvish will be ignored from Elvish 0.20.0.
The warning is due to the hardcoded path in package github.com/href/elvish-gitstatus:
# the folder where the gitstatusd related data is stored
var appdir = ~/.elvish/package-data/gitstatus
I would argue this should use $XDG_STATE_HOME (see https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html) or equivalent. The problem is that determining that directory is complicated since Elvish does not require the XDG env vars to be set and has fallbacks which differ between UNIX and Windows. It shouldn't be necessary for a module to implement this logic. See #1385 where I proposed exposing this information via the platform: module to make it trivial for modules to use whatever directory the current Elvish instance deems is appropriate for each type of file Elvish searches for (see https://elv.sh/ref/command.html).
For the moment I'm just going to locally edit github.com/href/elvish-gitstatus/gitstatus.elv but this needs to be resolved ASAP since ~/.elvish is now officially deprecated.