add git refresh
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
- [x] Mouse support
|
- [x] Mouse support
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
- [ ] refresh tree (for git) on file save and update git status when needed
|
|
||||||
- [ ] find a good way to display git info
|
- [ ] find a good way to display git info
|
||||||
- [ ] better parsing of the git porcelain results
|
- [ ] better parsing of the git porcelain results
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ local system = function(v) api.nvim_call_function('system', { v }) end
|
|||||||
local update_tree_view = require 'lib/winutils'.update_view
|
local update_tree_view = require 'lib/winutils'.update_view
|
||||||
local scratch_wrapper = require 'lib/winutils'.scratch_wrapper
|
local scratch_wrapper = require 'lib/winutils'.scratch_wrapper
|
||||||
local update_tree_state = require 'lib/state'.refresh_tree
|
local update_tree_state = require 'lib/state'.refresh_tree
|
||||||
|
local refresh_git = require 'lib/git'.refresh_git
|
||||||
|
|
||||||
local EDIT_FILE = nil
|
local EDIT_FILE = nil
|
||||||
|
|
||||||
@@ -20,14 +21,15 @@ local function edit_rename(filename, path)
|
|||||||
scratch_wrapper("rename", { "Rename " .. path, path .. filename })
|
scratch_wrapper("rename", { "Rename " .. path, path .. filename })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: for both 3 functions below, update git status before update_tree_state
|
|
||||||
local function add_file(path)
|
local function add_file(path)
|
||||||
if string.match(path, '.*/$') then
|
if string.match(path, '.*/$') then
|
||||||
system('mkdir -p ' .. path)
|
system('mkdir -p ' .. path)
|
||||||
|
refresh_git()
|
||||||
update_tree_state()
|
update_tree_state()
|
||||||
update_tree_view(true)
|
update_tree_view(true)
|
||||||
else
|
else
|
||||||
system('touch ' .. path)
|
system('touch ' .. path)
|
||||||
|
refresh_git()
|
||||||
update_tree_state()
|
update_tree_state()
|
||||||
update_tree_view(true)
|
update_tree_view(true)
|
||||||
end
|
end
|
||||||
@@ -37,6 +39,7 @@ end
|
|||||||
local function remove_file(confirmation)
|
local function remove_file(confirmation)
|
||||||
if string.match(confirmation, '^y/n: y.*$') ~= nil then
|
if string.match(confirmation, '^y/n: y.*$') ~= nil then
|
||||||
system('rm -rf ' .. EDIT_FILE)
|
system('rm -rf ' .. EDIT_FILE)
|
||||||
|
refresh_git()
|
||||||
update_tree_state()
|
update_tree_state()
|
||||||
update_tree_view(true)
|
update_tree_view(true)
|
||||||
end
|
end
|
||||||
@@ -48,6 +51,7 @@ local function rename_file(path)
|
|||||||
system('mv '..EDIT_FILE..' '..path)
|
system('mv '..EDIT_FILE..' '..path)
|
||||||
EDIT_FILE = nil
|
EDIT_FILE = nil
|
||||||
api.nvim_command("q!")
|
api.nvim_command("q!")
|
||||||
|
refresh_git()
|
||||||
update_tree_state()
|
update_tree_state()
|
||||||
update_tree_view(true)
|
update_tree_view(true)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,8 +15,14 @@ end
|
|||||||
local GIT_STATUS = set_git_status()
|
local GIT_STATUS = set_git_status()
|
||||||
|
|
||||||
local function refresh_git()
|
local function refresh_git()
|
||||||
IS_GIT_REPO = is_git_repo()
|
if IS_GIT_REPO == false then return false end
|
||||||
GIT_STATUS = set_git_status()
|
GIT_STATUS = set_git_status()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function force_refresh_git()
|
||||||
|
IS_GIT_REPO = is_git_repo()
|
||||||
|
refresh_git()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function is_folder_dirty(relpath)
|
local function is_folder_dirty(relpath)
|
||||||
@@ -54,4 +60,5 @@ end
|
|||||||
return {
|
return {
|
||||||
get_git_attr = get_git_attr;
|
get_git_attr = get_git_attr;
|
||||||
refresh_git = refresh_git;
|
refresh_git = refresh_git;
|
||||||
|
force_refresh_git = force_refresh_git;
|
||||||
}
|
}
|
||||||
|
|||||||
17
lua/tree.lua
17
lua/tree.lua
@@ -10,6 +10,7 @@ local get_tree = stateutils.get_tree
|
|||||||
local init_tree = stateutils.init_tree
|
local init_tree = stateutils.init_tree
|
||||||
local open_dir = stateutils.open_dir
|
local open_dir = stateutils.open_dir
|
||||||
local check_dir_access = stateutils.check_dir_access
|
local check_dir_access = stateutils.check_dir_access
|
||||||
|
local refresh_tree = stateutils.refresh_tree
|
||||||
|
|
||||||
local winutils = require 'lib/winutils'
|
local winutils = require 'lib/winutils'
|
||||||
local update_view = winutils.update_view
|
local update_view = winutils.update_view
|
||||||
@@ -22,6 +23,10 @@ local conf = require 'lib/conf'
|
|||||||
local set_root_path = conf.set_root_path
|
local set_root_path = conf.set_root_path
|
||||||
local get_cwd = conf.get_cwd
|
local get_cwd = conf.get_cwd
|
||||||
|
|
||||||
|
local git = require 'lib/git'
|
||||||
|
local refresh_git = git.refresh_git
|
||||||
|
local force_refresh_git = git.force_refresh_git
|
||||||
|
|
||||||
init_tree()
|
init_tree()
|
||||||
|
|
||||||
local function toggle()
|
local function toggle()
|
||||||
@@ -40,7 +45,6 @@ local function open_file(open_type)
|
|||||||
local node = tree[tree_index]
|
local node = tree[tree_index]
|
||||||
|
|
||||||
if node.name == '..' then
|
if node.name == '..' then
|
||||||
-- TODO: git update
|
|
||||||
api.nvim_command('cd ..')
|
api.nvim_command('cd ..')
|
||||||
|
|
||||||
local new_path
|
local new_path
|
||||||
@@ -51,15 +55,16 @@ local function open_file(open_type)
|
|||||||
end
|
end
|
||||||
|
|
||||||
set_root_path(new_path)
|
set_root_path(new_path)
|
||||||
|
force_refresh_git()
|
||||||
init_tree(new_path)
|
init_tree(new_path)
|
||||||
update_view()
|
update_view()
|
||||||
elseif open_type == 'chdir' then
|
elseif open_type == 'chdir' then
|
||||||
-- TODO: git update
|
|
||||||
if node.dir == false or check_dir_access(node.path .. node.name) == false then return end
|
if node.dir == false or check_dir_access(node.path .. node.name) == false then return end
|
||||||
|
|
||||||
api.nvim_command('cd ' .. node.path .. node.name)
|
api.nvim_command('cd ' .. node.path .. node.name)
|
||||||
local new_path = get_cwd() .. '/'
|
local new_path = get_cwd() .. '/'
|
||||||
set_root_path(new_path)
|
set_root_path(new_path)
|
||||||
|
force_refresh_git()
|
||||||
init_tree(new_path)
|
init_tree(new_path)
|
||||||
update_view()
|
update_view()
|
||||||
elseif node.dir == true then
|
elseif node.dir == true then
|
||||||
@@ -88,9 +93,17 @@ local function edit_file(edit_type)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function refresh()
|
||||||
|
if refresh_git() == true then
|
||||||
|
refresh_tree()
|
||||||
|
update_view()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
toggle = toggle;
|
toggle = toggle;
|
||||||
open_file = open_file;
|
open_file = open_file;
|
||||||
edit_file = edit_file;
|
edit_file = edit_file;
|
||||||
|
refresh = refresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ execute 'hi def LuaTreeGitUntracked gui=NONE guifg='.g:terminal_color_6
|
|||||||
execute 'hi def LuaTreeGitUnmerged gui=NONE guifg='.g:terminal_color_3
|
execute 'hi def LuaTreeGitUnmerged gui=NONE guifg='.g:terminal_color_3
|
||||||
execute 'hi def LuaTreeGitDirty gui=NONE guifg='.g:terminal_color_13
|
execute 'hi def LuaTreeGitDirty gui=NONE guifg='.g:terminal_color_13
|
||||||
|
|
||||||
|
au BufWritePost * lua require'tree'.refresh()
|
||||||
|
|
||||||
command! LuaTree lua require'tree'.toggle()
|
command! LuaTree lua require'tree'.toggle()
|
||||||
|
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
|
|||||||
Reference in New Issue
Block a user