From aa75e25f27f6cad66e5869ec1109084297eac65a Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 16 May 2020 14:44:16 +0100 Subject: Implement support for expanding ~ to the home directory. --- src/fileutils.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/fileutils.cpp') diff --git a/src/fileutils.cpp b/src/fileutils.cpp index c99673d22..f367b128c 100644 --- a/src/fileutils.cpp +++ b/src/fileutils.cpp @@ -76,6 +76,14 @@ std::string FileSystem::ExpandPath(const std::string& base, const std::string& f if (fragment[0] == '/' || FileSystem::StartsWithWindowsDriveLetter(fragment)) return fragment; + // The fragment is relative to a home directory, expand that. + if (fragment.compare(0, 2, "~/", 2)) + { + const char* homedir = getenv("HOME"); + if (homedir && *homedir) + return std::string(homedir) + '/' + fragment.substr(2); + } + return base + '/' + fragment; } -- cgit v1.3.1-10-gc9f91