summaryrefslogtreecommitdiff
path: root/src/fileutils.cpp
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2020-05-16 14:44:16 +0100
committerSadie Powell <sadie@witchery.services>2020-05-16 14:44:16 +0100
commitaa75e25f27f6cad66e5869ec1109084297eac65a (patch)
treebd62cb8cf4f08168edbfbf9b15e965e4800fc049 /src/fileutils.cpp
parent87bb27a7a794d413bd75ea17d4e1f83e207c8bdc (diff)
Implement support for expanding ~ to the home directory.
Diffstat (limited to 'src/fileutils.cpp')
-rw-r--r--src/fileutils.cpp8
1 files changed, 8 insertions, 0 deletions
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;
}