Avoid polluting $HOME by following XDG Base Directory Specification
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!
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.
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).
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.
~/.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 ...").
+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
~/.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_HOMEis defined, use$XDG_DATA_HOME/.zluaas a data file - else, use
~/.zlua
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.
The default should use $XDG_DATA_HOME, which is defined to ~/.local/share by default.
I heard that ~/.local/share is used to store read only data for programs, generated data should be in ~/.cache ??
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.
that's fair, I will update for this later. But people who is using z.lua currently will confuse why their history path disappear.
yep, that's a very important thing to handle.
How about:
- if
_ZL_DATAis defined, use that - elseif
~/.zluaexists use it - elseif
~/.zluadoes not exists and$XDG_DATA_HOMEis 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.