Expand "~/" in paths to $HOME/
This commit is contained in:
parent
d93953a929
commit
ec6d0eb8b7
@ -73,3 +73,17 @@ std::shared_ptr<std::vector<std::shared_ptr<std::string>>> 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;
|
||||
}
|
||||
|
@ -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<std::vector<std::shared_ptr<std::string>>> 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);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <unistd.h>
|
||||
#include <unordered_map>
|
||||
#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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user