Skip to content

Commit

Permalink
Support XDG_DATA_HOME
Browse files Browse the repository at this point in the history
Resolves #120
  • Loading branch information
jjcarstens committed Dec 22, 2020
1 parent e9bc12d commit 035a308
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/nerves_hub_cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ defmodule NervesHubCLI do
"""
@type fwup_public_key_ref :: String.t() | atom()

defguard valid_home_dir(dir) when is_binary(dir) and dir != ""

@spec default_description() :: String.t()
def default_description() do
{:ok, hostname} = :inet.gethostname()
Expand All @@ -20,10 +22,10 @@ defmodule NervesHubCLI do
override_dir =
Application.get_env(:nerves_hub_cli, :home_dir) || System.get_env("NERVES_HUB_HOME")

if override_dir == nil or override_dir == "" do
Path.expand("~/.nerves-hub")
else
override_dir
case {override_dir, System.get_env("XDG_DATA_HOME")} do
{dir, _} when valid_home_dir(dir) -> dir
{_, xdg} when valid_home_dir(xdg) -> Path.join(xdg, "nerves-hub")
_ -> Path.expand("~/.nerves-hub")
end
end

Expand Down

0 comments on commit 035a308

Please sign in to comment.