Adicionado configuração para enviar ao salvar
This commit is contained in:
@@ -3,6 +3,9 @@ local cli = require("nvim-sync-ftp.cli")
|
||||
local M = {}
|
||||
|
||||
function M.setup(opts)
|
||||
|
||||
local config = cli.getConfig()
|
||||
|
||||
vim.api.nvim_create_user_command("SyncFtpMapToRemote", function (params)
|
||||
cli.MapToRemote(params)
|
||||
end,{
|
||||
@@ -18,6 +21,25 @@ function M.setup(opts)
|
||||
nargs = '*',
|
||||
range = true,
|
||||
})
|
||||
|
||||
if next(config) ~= nil then
|
||||
-- Config for on save
|
||||
if config.upload_to_save == true then
|
||||
vim.api.nvim_create_augroup("SyncFtpUploadGroup", { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||
group = "SyncFtpUploadGroup",
|
||||
pattern = "*.*",
|
||||
callback = function(args)
|
||||
cli.Upload()
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -61,14 +61,17 @@ local function read_file(path)
|
||||
return lines
|
||||
end
|
||||
|
||||
local function getConfig()
|
||||
function M.getConfig()
|
||||
|
||||
local configTemp = {};
|
||||
|
||||
if file_exists() then
|
||||
local content, err = read_file(filePath)
|
||||
|
||||
if content then
|
||||
for i, line in ipairs(content) do
|
||||
local first_word, second_word = line:match("^(%S+)%s+(%S+)$")
|
||||
config[first_word] = second_word
|
||||
configTemp[first_word] = second_word
|
||||
end
|
||||
else
|
||||
message(err);
|
||||
@@ -76,11 +79,13 @@ local function getConfig()
|
||||
else
|
||||
message.error("Config file not found!")
|
||||
end
|
||||
|
||||
return configTemp
|
||||
end
|
||||
|
||||
function M.Upload()
|
||||
|
||||
getConfig()
|
||||
config = M.getConfig()
|
||||
local current_buffer_path = vim.api.nvim_buf_get_name(0)
|
||||
local directoryTemp = directory
|
||||
|
||||
|
||||
Reference in New Issue
Block a user