This repository has been archived by the owner on Nov 23, 2023. It is now read-only.
/
dot.erlang
49 lines (49 loc) · 2.08 KB
/
dot.erlang
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
%% If running an interactive shell
proplists:is_defined(noshell, init:get_arguments()) == false andalso begin
%% Depending on the install method DocshBase0 definition is rewritten
%% with sed or kept intact.
DocshBase0 = "$DOCSH_BASE",
NextStep = case {code:ensure_loaded(docsh), DocshBase0, os:getenv("DOCSH_BASE")} of
{{module, docsh}, _, _} ->
%% The code path already contains docsh.
ok;
{_, "$" ++ _, false} ->
%% If DocshBase0 starts with a $, the env variable of the same name
%% ought to be set. If it's not - we have a configuration error.
{error, env_not_set};
{_, "$" ++ _, Base} ->
{add_path, Base};
_ ->
%% We assume that if the env variable is not set and docsh is not loadable yet,
%% then DocshBase0 should've been expanded during installation to an absolute path.
{add_path, DocshBase0}
end,
case NextStep of
{error, env_not_set} ->
io:format("docsh error: DOCSH_BASE not set, docsh not enabled~n~n");
ok ->
docsh:activated(path);
{add_path, BasePath} ->
[ code:add_path(Dir)
|| Suffix <- ["/ebin", "/_build/default/lib/docsh/ebin"],
Dir <- [filename:join([BasePath, Suffix])],
filelib:is_dir(Dir) ],
code:add_path(BasePath ++ "/_build/default/lib/docsh/ebin"),
docsh:activated(path)
end,
case code:ensure_loaded(docsh) of
{error, _} ->
io:format("docsh error: docsh can't be loaded~n~n");
{module, docsh} ->
UserDefault = case os:getenv("DOCSH_USER_DEFAULT") of
false -> os:getenv("HOME") ++ "/.erlang.d/user_default";
[_|_] = Dir -> Dir
end,
case code:load_abs(UserDefault) of
{error, _} ->
io:format("docsh error: shell extensions not available~n~n");
{module, user_default} ->
docsh:activated(user_default)
end
end
end.