flutter_ecommerce_app icon indicating copy to clipboard operation
flutter_ecommerce_app copied to clipboard

Avoid polluting $HOME by following XDG Base Directory Specification

Open bengioe opened this issue 6 years ago • 12 comments

By default z.lua writes into ~/.zlua. This pollutes the home directory.

In Unix, writing in a specified config folder is preferable. Traditionally ~/.config/ serves this purpose.

In Windows %LOCALAPPDATA% serves this purpose.

In MacOS ~/Library/Preferences serves this purpose.

Thanks!

bengioe avatar Feb 04 '19 22:02 bengioe

There is a $_ZL_DATA environment variable can be used to specify your database name:

export _ZL_DATA="$HOME/.config/z.txt"

define this before init z.lua, and you can place the data file where ever you like.

skywind3000 avatar Feb 04 '19 22:02 skywind3000

It's great that z.lua has this feature, but I'm suggesting to change the default. Rather than have users look for such environment variables for every tool they install, we could make them happier by all placing our config files in ~/.config/ by default (plus changing the culture of polluting the home folder by default).

bengioe avatar Feb 04 '19 22:02 bengioe

If ~/.config does not exist, what can we do ? create one for user ?? I would rather create a file than create a directory in user's home directory.

Creating directories for user without notice or permission is the real pollution.

and, lua doesn't have a mkdir api.

skywind3000 avatar Feb 04 '19 23:02 skywind3000

~/.config is a standard base directory. The specification also says that the config dir should in fact be created if it doesn't already exist. Many other command line utilities conform to this standard.

Lua lacking mkdir functionality is definitely kind of a pain, but can be achieved with os.execute("mkdir ...").

Resonious avatar Feb 04 '19 23:02 Resonious

+1, ~/.config is the standard for dotfiles and it makes it also much easier to git your dotfiles, hence it would be awesome if you set this as the default

desmap avatar Feb 05 '19 09:02 desmap

~/.zlua is not a config file, it's a data file, so the logical way to store it is to use $XDG_DATA_HOME.

My guess is:

  • if $XDG_DATA_HOME is defined, use $XDG_DATA_HOME/.zlua as a data file
  • else, use ~/.zlua

BarbUk avatar Feb 05 '19 15:02 BarbUk

Ah, if it's data then yes $XDG_DATA_HOME sounds better. ~~Default~~ Fallback should be ~/.local/share/.zlua though if we want to be fully conformant.

EDIT: Clarity. Spec says we should create ~/.local/share if $XDG_DATA_HOME is blank.

Resonious avatar Feb 05 '19 15:02 Resonious

The default should use $XDG_DATA_HOME, which is defined to ~/.local/share by default.

BarbUk avatar Feb 05 '19 15:02 BarbUk

I heard that ~/.local/share is used to store read only data for programs, generated data should be in ~/.cache ??

skywind3000 avatar Feb 05 '19 15:02 skywind3000

From: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.

$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.

So ~/.local/share is the way to go.

BarbUk avatar Feb 05 '19 15:02 BarbUk

that's fair, I will update for this later. But people who is using z.lua currently will confuse why their history path disappear.

skywind3000 avatar Feb 05 '19 15:02 skywind3000

yep, that's a very important thing to handle.

How about:

  • if _ZL_DATA is defined, use that
  • elseif ~/.zlua exists use it
  • elseif ~/.zlua does not exists and $XDG_DATA_HOME is defined, DATA_FILE=$XDG_DATA_HOME/zlua
  • else use DATA_FILE=~./local/share/zlua

That way, existing user keep their history and new user will have a sane datafile default.

BarbUk avatar Feb 05 '19 15:02 BarbUk