Skip to content

Commit

Permalink
Cleanup how resolving home directory is happening a bit.
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Parpart <christian@parpart.family>
  • Loading branch information
christianparpart committed Oct 16, 2023
1 parent 5dc9f64 commit 8d16a58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/contour/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace
if (appTerminfoDir.has_value())
locations.emplace_back(appTerminfoDir.value().string());

locations.emplace_back(getenv("HOME") + "/.terminfo"s);
locations.emplace_back(Process::homeDirectory() / ".terminfo");

if (auto const* value = getenv("TERMINFO_DIRS"); value && *value)
for (auto const dir: crispy::split(string_view(value), ':'))
Expand Down Expand Up @@ -1893,8 +1893,8 @@ fs::path configHome(string const& programName)
#if defined(__unix__) || defined(__APPLE__)
if (auto const* value = getenv("XDG_CONFIG_HOME"); value && *value)
return fs::path { value } / programName;
else if (auto const* value = getenv("HOME"); value && *value)
return fs::path { value } / ".config" / programName;
else
return Process::homeDirectory() / ".config" / programName;
#endif

#if defined(_WIN32)
Expand All @@ -1906,9 +1906,8 @@ fs::path configHome(string const& programName)
GetEnvironmentVariableA("LOCALAPPDATA", &buf[0], size);
return fs::path { &buf[0] } / programName;
}
#endif

throw runtime_error { "Could not find config home folder." };
#endif
}

fs::path configHome()
Expand Down
4 changes: 3 additions & 1 deletion src/vtpty/Process_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ vector<string> Process::loginShell(bool escapeSandbox)

fs::path Process::homeDirectory()
{
if (passwd const* pw = getpwuid(getuid()); pw != nullptr)
if (auto const* home = getenv("HOME"); home != nullptr)
return fs::path(home);
else if (passwd const* pw = getpwuid(getuid()); pw != nullptr)
return fs::path(pw->pw_dir);
else
return fs::path("/");
Expand Down

0 comments on commit 8d16a58

Please sign in to comment.