diff --git a/src/core/Path.cc b/src/core/Path.cc index 6828055..268eb5c 100644 --- a/src/core/Path.cc +++ b/src/core/Path.cc @@ -73,3 +73,17 @@ std::shared_ptr>> Path::listdir(const s return result; } + +std::string Path::clean(const std::string & s) +{ + std::string p = s; + if (p.substr(0, 2) == "~/") + { + char * home = getenv("HOME"); + if (home != nullptr) + { + p = home + p.substr(1, p.size()); + } + } + return p; +} diff --git a/src/core/Path.h b/src/core/Path.h index 394dcf8..b30b500 100644 --- a/src/core/Path.h +++ b/src/core/Path.h @@ -19,6 +19,7 @@ public: static bool is_file(const std::string & s); static bool is_dir(const std::string & s); static std::shared_ptr>> listdir(const std::string & path); + static std::string clean(const std::string & s); protected: static std::string _join(const std::string & first, const std::string & second); diff --git a/src/gui/Window.cc b/src/gui/Window.cc index 7ca9445..b003a4e 100644 --- a/src/gui/Window.cc +++ b/src/gui/Window.cc @@ -7,6 +7,7 @@ #include #include #include "DefaultCommandMap.h" +#include "Path.h" #define INITIAL_WIDTH 800 #define INITIAL_HEIGHT 800 @@ -571,7 +572,7 @@ void Window::command_write_file(const CommandParser & cp) } if (path != "") { - buffer->write_to_file(path.c_str()); + buffer->write_to_file(Path::clean(path).c_str()); } }