local api = vim.apilocal buf, win
local function open_window() buf = api.nvim_create_buf(false,true)-- create new emtpy buffer
api.nvim_buf_set_option(buf,'bufhidden','wipe')-- get dimensions local width = api.nvim_get_option("columns") local height = api.nvim_get_option("lines")-- calculate our floating window size local win_height = math.ceil(height * 0.8 - 4) local win_width = math.ceil(width * 0.8)-- and its starting position local row = math.ceil((height - win_height) / 2 - 1) local col = math.ceil((width - win_width) / 2)-- set some options local opts = { style = "minimal", relative = "editor", width = win_width, height = win_height, row = row, col = col }-- and finally create it with buffer attached win = api.nvim_open_win(buf, true, opts)end
local function update_view()-- we will use vim systemlist function which run shell-- command and return result as list
local result = vim.fn.systemlist('git diff-tree --no-commit-id --name-only -r HEAD')-- with small indentation results will look better
for k,v in pairs(result) do
result[k]=' '..result[k]
end
api.nvim_buf_set_lines(buf,0,-1,false, result)
end
local function my_plugin()
position =0-- if you want to preserve last displayed state just omit this line
open_window()
set_mappings()
update_view(0)
api.nvim_win_set_cursor(win,{4,0})-- set cursor on first list entry
end
return {
my_plugin = my_plugin,
update_view = update_view,
open_file = open_file,
move_cursor = move_cursor,
close_window = close_window
}