-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathxdg.ex
More file actions
32 lines (28 loc) · 740 Bytes
/
xdg.ex
File metadata and controls
32 lines (28 loc) · 740 Bytes
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
defmodule ElixirLS.Utils.XDG do
@moduledoc """
Utilities for reading files within ElixirLS's XDG configuration directory
"""
@default_xdg_directory "$HOME/.config"
def read_elixir_ls_config_file(path) do
xdg_directory()
|> Path.join("elixir_ls")
|> Path.join(path)
|> File.read()
|> case do
{:ok, file_contents} -> {:ok, file_contents}
err -> err
end
end
defp xdg_directory do
case System.get_env("XDG_CONFIG_HOME") do
nil ->
@default_xdg_directory
xdg_directory ->
if File.dir?(xdg_directory) do
xdg_directory
else
raise "$XDG_CONFIG_HOME environment variable set, but directory does not exist"
end
end
end
end