View Source XDGBasedir (xdg_basedir v0.1.1)

Helpers for using directories per the XDG Base Directory Specification version 0.8.

Examples

iex> System.put_env("HOME", "/home/user")
:ok
iex> System.delete_env("XDG_CONFIG_HOME")
:ok
iex> XDGBasedir.user_config_dir
"/home/user/.config"
iex> XDGBasedir.user_config_dir("my_app")
"/home/user/.config/my_app"
iex> System.put_env("XDG_STATE_HOME", "/my/state/path")
:ok
iex> XDGBasedir.user_state_dir("my_app")
"/my/state/path/my_app"

Summary

Functions

Gets the list of config directories to search after the user config base directory, which is either parsed from the value of $XDG_CONFIG_DIRS or the default of ["/etc/xdg"].

Joins a provided relative path to each directory in the list of config directories.

Gets the list of data directories to search after the user data base directory, which is either parsed from the value of $XDG_DATA_DIRS or the default of ["/usr/local/share", "/usr/share"].

Joins a provided relative path to each directory in the list of data directories.

Gets the user executable base directory, which is $HOME/.local/bin always per the spec.

Gets the user cache base directory, which is either the value of $XDG_CACHE_HOME or the default of $HOME/.cache.

Joins a provided relative path to the user cache base directory.

Gets the user configuration base directory, which is either the value of $XDG_CONFIG_HOME or the default of $HOME/.config.

Joins a provided relative path to the user config base directory.

Gets the user data base directory, which is either the value of $XDG_DATA_HOME or the default of $HOME/.local/share.

Joins a provided relative path to the user data base directory.

Gets the user runtime base directory if it is set, which is the value of $XDG_RUNTIME_DIR.

Joins a provided relative path to the user runtime base directory if it is set.

Gets the user state base directory, which is either the value of $XDG_STATE_HOME or the default of $HOME/.local/state.

Joins a provided relative path to the user state base directory.

Functions

config_dirs()

@spec config_dirs() :: [Path.t()]

Gets the list of config directories to search after the user config base directory, which is either parsed from the value of $XDG_CONFIG_DIRS or the default of ["/etc/xdg"].

Examples

iex> System.delete_env("XDG_CONFIG_DIRS")
:ok
iex> XDGBasedir.config_dirs
["/etc/xdg"]
iex> System.put_env("XDG_CONFIG_DIRS", "/cfg/1:/cfg/2")
:ok
iex> XDGBasedir.config_dirs
["/cfg/1", "/cfg/2"]

config_dirs(path)

@spec config_dirs(Path.t()) :: Path.t()

Joins a provided relative path to each directory in the list of config directories.

Examples

iex> System.put_env("XDG_CONFIG_DIRS", "/cfg/1:/cfg/2")
:ok
iex> XDGBasedir.config_dirs("my_app")
["/cfg/1/my_app", "/cfg/2/my_app"]

data_dirs()

@spec data_dirs() :: [Path.t()]

Gets the list of data directories to search after the user data base directory, which is either parsed from the value of $XDG_DATA_DIRS or the default of ["/usr/local/share", "/usr/share"].

Examples

iex> System.delete_env("XDG_DATA_DIRS")
:ok
iex> XDGBasedir.data_dirs
["/usr/local/share", "/usr/share"]
iex> System.put_env("XDG_DATA_DIRS", "/data/1:/data/2")
:ok
iex> XDGBasedir.data_dirs
["/data/1", "/data/2"]

data_dirs(path)

@spec data_dirs(Path.t()) :: [Path.t()]

Joins a provided relative path to each directory in the list of data directories.

Examples

iex> System.put_env("XDG_DATA_DIRS", "/data/1:/data/2")
:ok
iex> XDGBasedir.data_dirs("my_app")
["/data/1/my_app", "/data/2/my_app"]

user_bin_dir()

@spec user_bin_dir() :: Path.t()

Gets the user executable base directory, which is $HOME/.local/bin always per the spec.

Examples

iex> System.put_env("HOME", "/home/user")
:ok
iex> XDGBasedir.user_bin_dir
"/home/user/.local/bin"

user_cache_dir()

@spec user_cache_dir() :: Path.t()

Gets the user cache base directory, which is either the value of $XDG_CACHE_HOME or the default of $HOME/.cache.

Examples

iex> System.put_env("HOME", "/home/user")
:ok
iex> System.delete_env("XDG_CACHE_HOME")
:ok
iex> XDGBasedir.user_cache_dir
"/home/user/.cache"
iex> System.put_env("XDG_CACHE_HOME", "/my/cache/path")
:ok
iex> XDGBasedir.user_cache_dir
"/my/cache/path"

user_cache_dir(path)

@spec user_cache_dir(Path.t()) :: Path.t()

Joins a provided relative path to the user cache base directory.

Examples

iex> System.put_env("XDG_CACHE_HOME", "/my/cache/path")
:ok
iex> XDGBasedir.user_cache_dir("my_app")
"/my/cache/path/my_app"

user_config_dir()

@spec user_config_dir() :: Path.t()

Gets the user configuration base directory, which is either the value of $XDG_CONFIG_HOME or the default of $HOME/.config.

Examples

iex> System.put_env("HOME", "/home/user")
:ok
iex> System.delete_env("XDG_CONFIG_HOME")
:ok
iex> XDGBasedir.user_config_dir
"/home/user/.config"
iex> System.put_env("XDG_CONFIG_HOME", "/my/config/path")
:ok
iex> XDGBasedir.user_config_dir
"/my/config/path"

user_config_dir(path)

@spec user_config_dir(Path.t()) :: Path.t()

Joins a provided relative path to the user config base directory.

Examples

iex> System.put_env("XDG_CONFIG_HOME", "/my/config/path")
:ok
iex> XDGBasedir.user_config_dir("my_app")
"/my/config/path/my_app"

user_data_dir()

@spec user_data_dir() :: Path.t()

Gets the user data base directory, which is either the value of $XDG_DATA_HOME or the default of $HOME/.local/share.

Examples

iex> System.put_env("HOME", "/home/user")
:ok
iex> System.delete_env("XDG_DATA_HOME")
:ok
iex> XDGBasedir.user_data_dir
"/home/user/.local/share"
iex> System.put_env("XDG_DATA_HOME", "/my/data/path")
:ok
iex> XDGBasedir.user_data_dir
"/my/data/path"

user_data_dir(path)

@spec user_data_dir(Path.t()) :: Path.t()

Joins a provided relative path to the user data base directory.

Examples

iex> System.put_env("XDG_DATA_HOME", "/my/data/path")
:ok
iex> XDGBasedir.user_data_dir("my_app")
"/my/data/path/my_app"

user_runtime_dir()

@spec user_runtime_dir() :: Path.t() | nil

Gets the user runtime base directory if it is set, which is the value of $XDG_RUNTIME_DIR.

Because the specification does not provide a default runtime base directory, returns nil if $XDG_RUNTIME_DIR is not set.

Examples

iex> System.delete_env("XDG_RUNTIME_DIR")
:ok
iex> XDGBasedir.user_runtime_dir
nil
iex> System.put_env("XDG_RUNTIME_DIR", "/my/runtime/path")
:ok
iex> XDGBasedir.user_runtime_dir
"/my/runtime/path"

user_runtime_dir(path)

@spec user_runtime_dir(Path.t()) :: Path.t() | nil

Joins a provided relative path to the user runtime base directory if it is set.

Because the specification does not provide a default runtime base directory, returns nil if $XDG_RUNTIME_DIR is not set.

Examples

iex> System.put_env("XDG_RUNTIME_DIR", "/my/runtime/path")
:ok
iex> XDGBasedir.user_runtime_dir("my_app")
"/my/runtime/path/my_app"

user_state_dir()

@spec user_state_dir() :: Path.t()

Gets the user state base directory, which is either the value of $XDG_STATE_HOME or the default of $HOME/.local/state.

Examples

iex> System.put_env("HOME", "/home/user")
:ok
iex> System.delete_env("XDG_STATE_HOME")
:ok
iex> XDGBasedir.user_state_dir
"/home/user/.local/state"
iex> System.put_env("XDG_STATE_HOME", "/my/state/path")
:ok
iex> XDGBasedir.user_state_dir
"/my/state/path"

user_state_dir(path)

@spec user_state_dir(Path.t()) :: Path.t()

Joins a provided relative path to the user state base directory.

Examples

iex> System.put_env("XDG_STATE_HOME", "/my/state/path")
:ok
iex> XDGBasedir.user_state_dir("my_app")
"/my/state/path/my_app"