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 = {}
|
local M = {}
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
|
|
||||||
|
local config = cli.getConfig()
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("SyncFtpMapToRemote", function (params)
|
vim.api.nvim_create_user_command("SyncFtpMapToRemote", function (params)
|
||||||
cli.MapToRemote(params)
|
cli.MapToRemote(params)
|
||||||
end,{
|
end,{
|
||||||
@@ -18,6 +21,25 @@ function M.setup(opts)
|
|||||||
nargs = '*',
|
nargs = '*',
|
||||||
range = true,
|
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
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -61,14 +61,17 @@ local function read_file(path)
|
|||||||
return lines
|
return lines
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getConfig()
|
function M.getConfig()
|
||||||
|
|
||||||
|
local configTemp = {};
|
||||||
|
|
||||||
if file_exists() then
|
if file_exists() then
|
||||||
local content, err = read_file(filePath)
|
local content, err = read_file(filePath)
|
||||||
|
|
||||||
if content then
|
if content then
|
||||||
for i, line in ipairs(content) do
|
for i, line in ipairs(content) do
|
||||||
local first_word, second_word = line:match("^(%S+)%s+(%S+)$")
|
local first_word, second_word = line:match("^(%S+)%s+(%S+)$")
|
||||||
config[first_word] = second_word
|
configTemp[first_word] = second_word
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
message(err);
|
message(err);
|
||||||
@@ -76,11 +79,13 @@ local function getConfig()
|
|||||||
else
|
else
|
||||||
message.error("Config file not found!")
|
message.error("Config file not found!")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return configTemp
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.Upload()
|
function M.Upload()
|
||||||
|
|
||||||
getConfig()
|
config = M.getConfig()
|
||||||
local current_buffer_path = vim.api.nvim_buf_get_name(0)
|
local current_buffer_path = vim.api.nvim_buf_get_name(0)
|
||||||
local directoryTemp = directory
|
local directoryTemp = directory
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user