Current section
Files
Jump to
Current section
Files
src/xdgleam.erl
-module(xdgleam).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([read_home/0, read_config_dirs/0, read_data_dirs/0, read_runtime_dirs/0, new/0]).
-export_type([base_directory/0, error/0, error_kind/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type base_directory() :: {base_directory,
binary(),
binary(),
binary(),
binary(),
list(binary()),
list(binary()),
gleam@option:option(binary())}.
-type error() :: {error, error_kind()}.
-type error_kind() :: any_error.
-file("src/xdgleam.gleam", 59).
?DOC(" Reads $HOME\n").
-spec read_home() -> {ok, binary()} | {error, nil}.
read_home() ->
Value = begin
_pipe = envoy_ffi:get(<<"HOME"/utf8>>),
gleam@result:unwrap(_pipe, <<""/utf8>>)
end,
{ok, Value}.
-file("src/xdgleam.gleam", 68).
?DOC(" Reads $XDG_CONFIG_DIRS\n").
-spec read_config_dirs() -> {ok, list(binary())} | {error, nil}.
read_config_dirs() ->
Value = begin
_pipe = envoy_ffi:get(<<"XDG_CONFIG_DIRS"/utf8>>),
gleam@result:unwrap(_pipe, <<""/utf8>>)
end,
{ok,
begin
_pipe@1 = Value,
gleam@string:split(_pipe@1, <<":"/utf8>>)
end}.
-file("src/xdgleam.gleam", 80).
?DOC(" Reads $XDG_CONFIG_DIRS\n").
-spec read_data_dirs() -> {ok, list(binary())} | {error, nil}.
read_data_dirs() ->
Value = begin
_pipe = envoy_ffi:get(<<"XDG_DATA_DIRS"/utf8>>),
gleam@result:unwrap(_pipe, <<""/utf8>>)
end,
{ok,
begin
_pipe@1 = Value,
gleam@string:split(_pipe@1, <<":"/utf8>>)
end}.
-file("src/xdgleam.gleam", 92).
?DOC(" Reads $XDG_RUNTIME_DIR\n").
-spec read_runtime_dirs() -> {ok, gleam@option:option(binary())} | {error, nil}.
read_runtime_dirs() ->
Value = begin
_pipe = envoy_ffi:get(<<"XDG_RUNTIME_DIR"/utf8>>),
gleam@result:unwrap(_pipe, <<""/utf8>>)
end,
{ok, {some, Value}}.
-file("src/xdgleam.gleam", 27).
-spec new() -> base_directory().
new() ->
Home_directory = begin
_pipe = read_home(),
gleam@result:unwrap(_pipe, <<""/utf8>>)
end,
Config_directories = begin
_pipe@1 = read_config_dirs(),
gleam@result:unwrap(_pipe@1, [<<"/etc/xdg"/utf8>>])
end,
Data_directories = begin
_pipe@2 = read_data_dirs(),
gleam@result:unwrap(
_pipe@2,
[<<"/usr/local/share"/utf8>>, <<"/usr/share"/utf8>>]
)
end,
Runtime_directory = begin
_pipe@3 = read_runtime_dirs(),
gleam@result:unwrap(_pipe@3, none)
end,
{base_directory,
filepath:join(Home_directory, <<".local/share"/utf8>>),
filepath:join(Home_directory, <<".config"/utf8>>),
filepath:join(Home_directory, <<".cache"/utf8>>),
filepath:join(Home_directory, <<".local/state"/utf8>>),
Data_directories,
Config_directories,
Runtime_directory}.