reformat, refactor code, run fs command with luv.spawn

This commit is contained in:
kiyan42
2020-04-26 14:13:09 +02:00
parent 81ee46e41d
commit 697912429c
9 changed files with 679 additions and 704 deletions

View File

@@ -1,72 +1,68 @@
local api = vim.api
local fs = require 'lib/fs'
local update_view = require 'lib/winutils'.update_view
local refresh_tree = require 'lib/state'.refresh_tree
local refresh_git = require 'lib/git'.refresh_git
local utils = require'lib/utils'
local fs = require 'lib/fs'
local rm = fs.rm
local rename = fs.rename
local create = fs.create
local M = {}
local function input(v)
local param
if type(v) == 'string' then param = { v } else param = v end
return api.nvim_call_function('input', param)
local param
if type(v) == 'string' then param = { v } else param = v end
return api.nvim_call_function('input', param)
end
local function clear_prompt()
api.nvim_command('normal :<esc>')
api.nvim_command('normal :<esc>')
end
local function create_file(path)
local new_file = input("Create file: " .. path)
function M.create_file(path)
local new_file = input("Create file: " .. path)
local file = nil
if not new_file:match('.*/$') then
file = new_file:reverse():gsub('/.*$', ''):reverse()
new_file = new_file:gsub('[^/]*$', '')
local file = nil
if not new_file:match('.*/$') then
file = new_file:reverse():gsub('/.*$', ''):reverse()
new_file = new_file:gsub('[^/]*$', '')
end
local folders = ""
if #new_file ~= 0 then
for p in new_file:gmatch('[^/]*') do
if p and p ~= "" then
folders = folders .. p .. '/'
end
end
end
local folders = ""
if #new_file ~= 0 then
for p in new_file:gmatch('[^/]*') do
if p and p ~= "" then
folders = folders .. p .. '/'
end
end
end
clear_prompt()
create(path, file, folders)
clear_prompt()
fs.create(path, file, folders, function()
refresh_git()
refresh_tree()
update_view()
end)
end
local function remove_file(filename, path)
local ans = input("Remove " .. filename .. " ? y/n: ")
clear_prompt()
if ans == "y" then
rm(path .. filename)
refresh_git()
refresh_tree()
update_view()
end
function M.remove_file(filename, path)
local ans = input("Remove " .. filename .. " ? y/n: ")
clear_prompt()
if ans == "y" then
fs.rm(path .. filename, function()
refresh_git()
refresh_tree()
update_view()
end)
end
end
local function rename_file(filename, path)
local new_path = input({"Rename file " .. filename .. ": ", path .. filename})
clear_prompt()
rename(path .. filename, new_path)
function M.rename_file(filename, path)
local new_path = input({"Rename file " .. filename .. ": ", path .. filename})
clear_prompt()
fs.rename(path .. filename, new_path, function()
refresh_git()
refresh_tree()
update_view()
end)
end
return {
create_file = create_file;
remove_file = remove_file;
rename_file = rename_file;
}
return M