Write file to argument given to 'w' command, if present

This commit is contained in:
Josh Holtrop 2018-03-20 21:19:23 -04:00
parent 909e56d5af
commit 8d158e4ed9
2 changed files with 19 additions and 2 deletions

View File

@ -83,6 +83,10 @@ public:
{
return !(*this == s);
}
std::string to_string() const
{
return std::string((const char *)&(*m_data)[0], m_size);
}
protected:
Encoding::Type m_encoding;

View File

@ -552,9 +552,22 @@ void Window::handle_command(const EncodedString & command)
void Window::command_write_file(const CommandParser & cp)
{
std::shared_ptr<Buffer> buffer = m_focused_buffer_pane->buffer();
if (buffer->filename())
std::string path;
if (cp.size() >= 2)
{
buffer->write_to_file(buffer->filename()->c_str());
path = cp[1].to_string();
}
else
{
auto filename = buffer->filename();
if (filename)
{
path = *filename;
}
}
if (path != "")
{
buffer->write_to_file(path.c_str());
}
}