sb logoToday I Learned

1 post about #erlang

Respecting XDG Settings

The XDG spec is a way for users to define where files get created. I was recently working on a feature that stores a local cache and local configs and found an easy way to determine that path for a user using Elixir/Erlang. Filename.basedir/2 was added in OTP19 for just this purpose.

iex(1)> :filename.basedir(:user_config, "simplebet")

iex(2)> System.put_env("XDG_CONFIG_HOME", "/home/todd/configs/")    

iex(3)> :filename.basedir(:user_config, "simplebet")            

Notice when the environment variable “XDG_CONFIG_HOME” is present, Erlang uses that value to build the path.