From bfa0e8705eb83a0724aed6d5dc9d21aa62a8986b Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Tue, 22 Aug 2023 13:19:03 -0700 Subject: [PATCH] fix: errors when writing files over ssh (#159) --- lua/oil/adapters/ssh.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/oil/adapters/ssh.lua b/lua/oil/adapters/ssh.lua index ac7ac93..142b076 100644 --- a/lua/oil/adapters/ssh.lua +++ b/lua/oil/adapters/ssh.lua @@ -391,16 +391,17 @@ M.write_file = function(bufnr) vim.loop.fs_close(fd) end vim.cmd.doautocmd({ args = { "BufWritePre", bufname }, mods = { silent = true } }) - vim.cmd.write({ args = { tmpfile }, bang = true, mods = { silent = true } }) + vim.cmd.write({ args = { tmpfile }, bang = true, mods = { silent = true, noautocmd = true } }) local tmp_bufnr = vim.fn.bufadd(tmpfile) shell.run({ "scp", "-C", tmpfile, scp_url }, function(err) + vim.bo[bufnr].modifiable = true if err then vim.notify(string.format("Error writing file: %s", err), vim.log.levels.ERROR) + else + vim.bo[bufnr].modified = false + vim.cmd.doautocmd({ args = { "BufWritePost", bufname }, mods = { silent = true } }) end - vim.bo[bufnr].modifiable = true - vim.bo[bufnr].modified = false - vim.cmd.doautocmd({ args = { "BufWritePost", bufname }, mods = { silent = true } }) vim.loop.fs_unlink(tmpfile) vim.api.nvim_buf_delete(tmp_bufnr, { force = true }) end)