From 7a41db2131ed87fa3e9d888207f17891342b8049 Mon Sep 17 00:00:00 2001 From: thefux Date: Fri, 11 Feb 2022 22:16:12 +0100 Subject: [PATCH 1/8] add telescope extension ^& small refactoring (still not done) --- lua/lazygit.lua | 53 ++++++++++-- .../_extensions/lazygit_telescope.lua | 84 +++++++++++++++++++ 2 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 lua/telescope/_extensions/lazygit_telescope.lua diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 44f79d4..ec2e293 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -2,6 +2,19 @@ vim = vim local api = vim.api local fn = vim.fn +-- store all git repositories visited in this session +local lazygit_visited_git_repos = {} +local function append_git_repo_path(repo_path) + -- TODO: could be done better :) + for _, path in ipairs(lazygit_visited_git_repos) do + if path == repo_path then + return + end + end + + table.insert(lazygit_visited_git_repos, tostring(repo_path)) +end + LAZYGIT_BUFFER = nil LAZYGIT_LOADED = false vim.g.lazygit_opened = 0 @@ -31,19 +44,25 @@ local function project_root_dir() end -- try symlinked file location instead - gitdir = fn.system( + local gitdir = fn.system( 'cd "' .. fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h') .. '" && git rev-parse --show-toplevel') - isgitdir = fn.matchstr(gitdir, '^fatal:.*') == '' + local isgitdir = fn.matchstr(gitdir, '^fatal:.*') == '' + + -- TODO: not sure the right way to do this if isgitdir then vim.o.shell = oldshell + append_git_repo_path(gitdir) return trim(gitdir) end -- revert to old shell vim.o.shell = oldshell + local repo_path = fn.getcwd(0, 0) + append_git_repo_path(repo_path) + -- just return current working directory - return fn.getcwd(0, 0) + return repo_path end --- on_exit callback function to delete the open buffer when lazygit exits in a neovim terminal @@ -158,13 +177,30 @@ local function lazygit(path) end end open_floating_window() + + -- TODO: this should be configurable and not hardcoded like this + -- this is convinient if you want to carry your lazygit config in a custom location + local function get_nvim_root() + local nvim_root_path = vim.api.nvim_eval('$MYVIMRC') + return nvim_root_path:match("(.*".."\\"..")") + end local cmd = 'lazygit' - if path ~= nil and not vim.env.GIT_DIR then - cmd = cmd .. ' -g "' .. path .. '/.git/"' - end - if path ~= nil and not vim.env.GIT_WORK_TREE then - cmd = cmd .. ' -w "' .. path .. '"' + _ = project_root_dir() + + if path ~= nil then + cmd = cmd .. ' -p ' .. path end + + cmd = cmd .. ' -ucf=' .. get_nvim_root() .. '/config/config.yml' + + -- if path ~= nil and not vim.env.GIT_DIR then + -- cmd = cmd .. ' -g "' .. path .. '/.git/"' + -- end + + -- if path ~= nil and not vim.env.GIT_WORK_TREE then + -- cmd = cmd .. ' -w "' .. path .. '"' + -- end + exec_lazygit_command(cmd) end @@ -217,4 +253,5 @@ return { lazygitfilter = lazygitfilter, lazygitconfig = lazygitconfig, project_root_dir = project_root_dir, + lazygit_visited_git_repos = lazygit_visited_git_repos, } diff --git a/lua/telescope/_extensions/lazygit_telescope.lua b/lua/telescope/_extensions/lazygit_telescope.lua new file mode 100644 index 0000000..ab9fd72 --- /dev/null +++ b/lua/telescope/_extensions/lazygit_telescope.lua @@ -0,0 +1,84 @@ +local Path = require("plenary.path") +local Window = require("plenary.window.float") +local strings = require("plenary.strings") +local pickers = require("telescope.pickers") +local finders = require("telescope.finders") +local actions = require("telescope.actions") +local utils = require("telescope.utils") +local action_set = require("telescope.actions.set") +local action_state = require("telescope.actions.state") +local conf = require("telescope.config").values +local lazygit = require("lazygit") + + +local function lazygit_toggle(path) + local cmd = [[lua require"lazygit".lazygit('%s')]] + cmd= cmd:format(path:gsub("%s", "")) + vim.api.nvim_command(cmd) + vim.api.nvim_buf_set_keymap(0, 't', '', '', {noremap = true, silent = true}) +end + +local function open_lazygit(prompt_buf) + actions.close(prompt_buf) + local entry = action_state.get_selected_entry() + lazygit_toggle(entry.value) +end + + +local lazygit_repos = function(opts) + local displayer = require("telescope.pickers.entry_display").create { + separator = "", + items = { + {width = 4}, + {width = 55}, + {remaining = true}, + }, + } + + local repos = {} + for _, v in pairs(lazygit.lazygit_visited_git_repos) do + local index = #repos + 1 + -- retrieve the git repo name + local entry = + { + idx = index, + value = v:gsub("%s", ""), + repo_name= v:gsub("%s", ""):match("^.+/(.+)$"), + } + + table.insert(repos, index, entry) + end + + pickers.new(opts or {}, { + prompt_title = "lazygit repos", + finder = finders.new_table { + results = repos, + entry_maker = function(entry) + local make_display = function() + return displayer + { + {entry.idx}, + {entry.repo_name}, + } + end + + return { + value = entry.value, + ordinal = string.format("%s %s", entry.idx, entry.repo_name), + display = make_display, + } + end, + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(_, _) + action_set.select:replace(open_lazygit) + return true + end + }):find() +end + +return require("telescope").register_extension({ + exports = { + lazygit = lazygit_repos, + } +}) From 4b3f42514b4a67e8391bb2a515728ab86d72235d Mon Sep 17 00:00:00 2001 From: thefux Date: Sun, 20 Feb 2022 20:54:47 +0100 Subject: [PATCH 2/8] update telescope plugin --- lua/telescope/_extensions/lazygit_telescope.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lua/telescope/_extensions/lazygit_telescope.lua b/lua/telescope/_extensions/lazygit_telescope.lua index ab9fd72..f3f0957 100644 --- a/lua/telescope/_extensions/lazygit_telescope.lua +++ b/lua/telescope/_extensions/lazygit_telescope.lua @@ -11,19 +11,15 @@ local conf = require("telescope.config").values local lazygit = require("lazygit") -local function lazygit_toggle(path) +local function open_lazygit(prompt_buf) + local entry = action_state.get_selected_entry() local cmd = [[lua require"lazygit".lazygit('%s')]] - cmd= cmd:format(path:gsub("%s", "")) + local path = entry.value + cmd = cmd:format(path:gsub("%s", "")) vim.api.nvim_command(cmd) vim.api.nvim_buf_set_keymap(0, 't', '', '', {noremap = true, silent = true}) end -local function open_lazygit(prompt_buf) - actions.close(prompt_buf) - local entry = action_state.get_selected_entry() - lazygit_toggle(entry.value) -end - local lazygit_repos = function(opts) local displayer = require("telescope.pickers.entry_display").create { From 5e121d88da8559e0c52074916c6bca49c9cd4736 Mon Sep 17 00:00:00 2001 From: thefux Date: Mon, 21 Feb 2022 20:27:36 +0100 Subject: [PATCH 3/8] clean up --- lua/lazygit.lua | 34 +++++-------------- .../_extensions/lazygit_telescope.lua | 6 +--- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index ec2e293..b5f4f83 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -5,7 +5,6 @@ local fn = vim.fn -- store all git repositories visited in this session local lazygit_visited_git_repos = {} local function append_git_repo_path(repo_path) - -- TODO: could be done better :) for _, path in ipairs(lazygit_visited_git_repos) do if path == repo_path then return @@ -36,7 +35,6 @@ end --- Get project_root_dir for git repository local function project_root_dir() - -- always use bash on Unix based systems. local oldshell = vim.o.shell if vim.fn.has('win32') == 0 then @@ -48,7 +46,6 @@ local function project_root_dir() 'cd "' .. fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h') .. '" && git rev-parse --show-toplevel') local isgitdir = fn.matchstr(gitdir, '^fatal:.*') == '' - -- TODO: not sure the right way to do this if isgitdir then vim.o.shell = oldshell append_git_repo_path(gitdir) @@ -171,36 +168,21 @@ local function lazygit(path) print('Please install lazygit. Check documentation for more information') return end + + open_floating_window() + + local cmd = 'lazygit' + -- set path to the root path + _ = project_root_dir() + if path == nil then if is_symlink() then path = project_root_dir() end - end - open_floating_window() - - -- TODO: this should be configurable and not hardcoded like this - -- this is convinient if you want to carry your lazygit config in a custom location - local function get_nvim_root() - local nvim_root_path = vim.api.nvim_eval('$MYVIMRC') - return nvim_root_path:match("(.*".."\\"..")") - end - local cmd = 'lazygit' - _ = project_root_dir() - - if path ~= nil then + else cmd = cmd .. ' -p ' .. path end - cmd = cmd .. ' -ucf=' .. get_nvim_root() .. '/config/config.yml' - - -- if path ~= nil and not vim.env.GIT_DIR then - -- cmd = cmd .. ' -g "' .. path .. '/.git/"' - -- end - - -- if path ~= nil and not vim.env.GIT_WORK_TREE then - -- cmd = cmd .. ' -w "' .. path .. '"' - -- end - exec_lazygit_command(cmd) end diff --git a/lua/telescope/_extensions/lazygit_telescope.lua b/lua/telescope/_extensions/lazygit_telescope.lua index f3f0957..6ccfb0e 100644 --- a/lua/telescope/_extensions/lazygit_telescope.lua +++ b/lua/telescope/_extensions/lazygit_telescope.lua @@ -1,10 +1,5 @@ -local Path = require("plenary.path") -local Window = require("plenary.window.float") -local strings = require("plenary.strings") local pickers = require("telescope.pickers") local finders = require("telescope.finders") -local actions = require("telescope.actions") -local utils = require("telescope.utils") local action_set = require("telescope.actions.set") local action_state = require("telescope.actions.state") local conf = require("telescope.config").values @@ -24,6 +19,7 @@ end local lazygit_repos = function(opts) local displayer = require("telescope.pickers.entry_display").create { separator = "", + -- TODO: make use of telescope geometry items = { {width = 4}, {width = 55}, From eb880dcd4dbbf80d8844e7da179a612cdfee509d Mon Sep 17 00:00:00 2001 From: thefux Date: Tue, 1 Mar 2022 21:37:45 +0100 Subject: [PATCH 4/8] update current working dir manually after selecting a repo --- lua/telescope/_extensions/lazygit_telescope.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/telescope/_extensions/lazygit_telescope.lua b/lua/telescope/_extensions/lazygit_telescope.lua index 76887b3..f913e3d 100644 --- a/lua/telescope/_extensions/lazygit_telescope.lua +++ b/lua/telescope/_extensions/lazygit_telescope.lua @@ -8,8 +8,10 @@ local lazygit = require("lazygit") local function open_lazygit(prompt_buf) local entry = action_state.get_selected_entry() - local cmd = [[lua require"lazygit".lazygit('%s')]] + local cmd = [[lua require"lazygit".lazygit(nil)]] cmd = cmd:format(entry.value:gsub("%s", "")) + + vim.fn.execute('cd ' .. entry.value) vim.api.nvim_command(cmd) vim.cmd('stopinsert') vim.cmd([[execute "normal i"]]) From b419f3e8d1d030576d7f8df6c7f8dfd0da05ee7e Mon Sep 17 00:00:00 2001 From: thefux Date: Sun, 6 Mar 2022 11:18:41 +0100 Subject: [PATCH 5/8] small refactoring --- lua/lazygit.lua | 163 ++---------------- lua/lazygit/utils.lua | 97 +++++++++++ lua/lazygit/window.lua | 85 +++++++++ .../_extensions/lazygit_telescope.lua | 4 +- 4 files changed, 203 insertions(+), 146 deletions(-) create mode 100644 lua/lazygit/utils.lua create mode 100644 lua/lazygit/window.lua diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 5f94602..895c1cd 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -1,80 +1,33 @@ -vim = vim -local api = vim.api +local open_floating_window = require"lazygit.window".open_floating_window +local project_root_dir = require"lazygit.utils".project_root_dir +local is_lazygit_available = require"lazygit.utils".is_lazygit_available +local is_symlink = require"lazygit.utils".is_symlink + local fn = vim.fn --- store all git repositories visited in this session -local lazygit_visited_git_repos = {} -local function append_git_repo_path(repo_path) - if repo_path == nil or not fn.isdirectory(repo_path) then - return - end - - for _, path in ipairs(lazygit_visited_git_repos) do - if path == repo_path then - return - end - end - - table.insert(lazygit_visited_git_repos, tostring(repo_path)) -end - LAZYGIT_BUFFER = nil LAZYGIT_LOADED = false vim.g.lazygit_opened = 0 ---- Strip leading and lagging whitespace -local function trim(str) - return str:gsub('^%s+', ''):gsub('%s+$', '') -end +local function clean_up_after_exit() + -- Close the window where the LAZYGIT_BUFFER is + vim.cmd('silent! :q') + LAZYGIT_BUFFER = nil + LAZYGIT_LOADED = false + vim.g.lazygit_opened = 0 ---- Check if lazygit is available -local function is_lazygit_available() - return fn.executable('lazygit') == 1 -end - -local function is_symlink() - local resolved = fn.resolve(fn.expand('%:p')) - return resolved ~= fn.expand('%:p') -end - ---- Get project_root_dir for git repository -local function project_root_dir() - -- always use bash on Unix based systems. - local oldshell = vim.o.shell - if vim.fn.has('win32') == 0 then - vim.o.shell = 'bash' - end - - -- try symlinked file location instead - local gitdir = fn.system( - 'cd "' .. fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h') .. '" && git rev-parse --show-toplevel') - local isgitdir = fn.matchstr(gitdir, '^fatal:.*') == '' - - if isgitdir then - vim.o.shell = oldshell - append_git_repo_path(gitdir) - return trim(gitdir) - end - - -- revert to old shell - vim.o.shell = oldshell - - local repo_path = fn.getcwd(0, 0) - append_git_repo_path(repo_path) - - -- just return current working directory - return repo_path + -- make sure to update current open buffer after closing the window + -- + vim.cmd('silent! :checktime') end --- on_exit callback function to delete the open buffer when lazygit exits in a neovim terminal local function on_exit(job_id, code, event) - if code == 0 then - -- Close the window where the LAZYGIT_BUFFER is - vim.cmd('silent! :q') - LAZYGIT_BUFFER = nil - LAZYGIT_LOADED = false - vim.g.lazygit_opened = 0 + if code ~= 0 then + return end + + clean_up_after_exit() end --- Call lazygit @@ -87,84 +40,6 @@ local function exec_lazygit_command(cmd) vim.cmd 'startinsert' end ---- open floating window with nice borders -local function open_floating_window() - local floating_window_scaling_factor = vim.g.lazygit_floating_window_scaling_factor - - -- Why is this required? - -- vim.g.lazygit_floating_window_scaling_factor returns different types if the value is an integer or float - if type(floating_window_scaling_factor) == 'table' then - floating_window_scaling_factor = floating_window_scaling_factor[false] - end - - local status, plenary = pcall(require, 'plenary.window.float') - if status and vim.g.lazygit_floating_window_use_plenary and vim.g.lazygit_floating_window_use_plenary ~= 0 then - plenary.percentage_range_window(floating_window_scaling_factor, floating_window_scaling_factor) - return - end - - local height = math.ceil(vim.o.lines * floating_window_scaling_factor) - 1 - local width = math.ceil(vim.o.columns * floating_window_scaling_factor) - - local row = math.ceil(vim.o.lines - height) / 2 - local col = math.ceil(vim.o.columns - width) / 2 - - local border_opts = { - style = 'minimal', - relative = 'editor', - row = row - 1, - col = col - 1, - width = width + 2, - height = height + 2, - } - - local opts = { style = 'minimal', relative = 'editor', row = row, col = col, width = width, height = height } - - local topleft, topright, botleft, botright - local corner_chars = vim.g.lazygit_floating_window_corner_chars - if type(corner_chars) == 'table' and #corner_chars == 4 then - topleft, topright, botleft, botright = unpack(corner_chars) - else - topleft, topright, botleft, botright = '╭', '╮', '╰', '╯' - end - - local border_lines = { topleft .. string.rep('─', width) .. topright } - local middle_line = '│' .. string.rep(' ', width) .. '│' - for i = 1, height do - table.insert(border_lines, middle_line) - end - table.insert(border_lines, botleft .. string.rep('─', width) .. botright) - - -- create a unlisted scratch buffer for the border - local border_buffer = api.nvim_create_buf(false, true) - - -- set border_lines in the border buffer from start 0 to end -1 and strict_indexing false - api.nvim_buf_set_lines(border_buffer, 0, -1, true, border_lines) - -- create border window - local border_window = api.nvim_open_win(border_buffer, true, border_opts) - vim.cmd('set winhl=Normal:Floating') - - -- create a unlisted scratch buffer - if LAZYGIT_BUFFER == nil or vim.fn.bufwinnr(LAZYGIT_BUFFER) == -1 then - LAZYGIT_BUFFER = api.nvim_create_buf(false, true) - else - LAZYGIT_LOADED = true - end - -- create file window, enter the window, and use the options defined in opts - local _ = api.nvim_open_win(LAZYGIT_BUFFER, true, opts) - - vim.bo[LAZYGIT_BUFFER].filetype = 'lazygit' - - vim.cmd('setlocal bufhidden=hide') - vim.cmd('setlocal nocursorcolumn') - vim.cmd('set winblend=' .. vim.g.lazygit_floating_window_winblend) - - -- use autocommand to ensure that the border_buffer closes at the same time as the main buffer - local cmd = [[autocmd WinLeave silent! execute 'hide']] - vim.cmd(cmd) - cmd = [[autocmd WinLeave silent! execute 'silent bdelete! %s']] - vim.cmd(cmd:format(border_buffer)) -end --- :LazyGit entry point local function lazygit(path) @@ -176,6 +51,7 @@ local function lazygit(path) open_floating_window() local cmd = 'lazygit' + -- set path to the root path _ = project_root_dir() @@ -241,5 +117,4 @@ return { lazygitfilter = lazygitfilter, lazygitconfig = lazygitconfig, project_root_dir = project_root_dir, - lazygit_visited_git_repos = lazygit_visited_git_repos, } diff --git a/lua/lazygit/utils.lua b/lua/lazygit/utils.lua new file mode 100644 index 0000000..2b34859 --- /dev/null +++ b/lua/lazygit/utils.lua @@ -0,0 +1,97 @@ +local fn = vim.fn + +-- store all git repositories visited in this session +local lazygit_visited_git_repos = {} + +-- TODO:check if the repo isa git repo +local function append_git_repo_path(repo_path) + if repo_path == nil or not fn.isdirectory(repo_path) then + return + end + + for _, path in ipairs(lazygit_visited_git_repos) do + if path == repo_path then + return + end + end + + table.insert(lazygit_visited_git_repos, tostring(repo_path)) +end + + +--- Strip leading and lagging whitespace +local function trim(str) + return str:gsub('^%s+', ''):gsub('%s+$', '') +end + + +local function get_root() + local cwd = vim.loop.cwd() + local status, job = pcall(require, 'plenary.job') + if not status then + local gitdir = fn.system('git rev-parse --show-toplevel') + end + + local gitroot_job = job:new({ + 'git', + 'rev-parse', + '--show-toplevel', + cwd=cwd + }) + + local _, code = gitroot_job:sync() + if (code ~= 0) then + return nil + end + + return fn.getcwd(0, 0) +end + +--- Get project_root_dir for git repository +local function project_root_dir() + -- always use bash on Unix based systems. + local oldshell = vim.o.shell + if vim.fn.has('win32') == 0 then + vim.o.shell = 'bash' + end + + local root = get_root() + -- try symlinked file location instead + local gitdir = fn.system( + 'cd "' .. fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h') .. '" && git rev-parse --show-toplevel') + local isgitdir = fn.matchstr(gitdir, '^fatal:.*') == '' + + if isgitdir then + vim.o.shell = oldshell + append_git_repo_path(gitdir) + return trim(gitdir) + end + + -- revert to old shell + vim.o.shell = oldshell + + local repo_path = fn.getcwd(0, 0) + append_git_repo_path(repo_path) + + -- just return current working directory + return repo_path +end + +--- Check if lazygit is available +local function is_lazygit_available() + return fn.executable('lazygit') == 1 +end + +local function is_symlink() + local resolved = fn.resolve(fn.expand('%:p')) + return resolved ~= fn.expand('%:p') +end + + +return { + get_root = get_root, + project_root_dir = project_root_dir, + lazygit_visited_git_repos = lazygit_visited_git_repos, + is_lazygit_available = is_lazygit_available, + is_symlink = is_symlink, +} diff --git a/lua/lazygit/window.lua b/lua/lazygit/window.lua new file mode 100644 index 0000000..9d2a5eb --- /dev/null +++ b/lua/lazygit/window.lua @@ -0,0 +1,85 @@ +local api = vim.api + + +--- open floating window with nice borders +local function open_floating_window() + local floating_window_scaling_factor = vim.g.lazygit_floating_window_scaling_factor + + -- Why is this required? + -- vim.g.lazygit_floating_window_scaling_factor returns different types if the value is an integer or float + if type(floating_window_scaling_factor) == 'table' then + floating_window_scaling_factor = floating_window_scaling_factor[false] + end + + local status, plenary = pcall(require, 'plenary.window.float') + if status and vim.g.lazygit_floating_window_use_plenary and vim.g.lazygit_floating_window_use_plenary ~= 0 then + plenary.percentage_range_window(floating_window_scaling_factor, floating_window_scaling_factor) + return + end + + local height = math.ceil(vim.o.lines * floating_window_scaling_factor) - 1 + local width = math.ceil(vim.o.columns * floating_window_scaling_factor) + + local row = math.ceil(vim.o.lines - height) / 2 + local col = math.ceil(vim.o.columns - width) / 2 + + local border_opts = { + style = 'minimal', + relative = 'editor', + row = row - 1, + col = col - 1, + width = width + 2, + height = height + 2, + } + + local opts = { style = 'minimal', relative = 'editor', row = row, col = col, width = width, height = height } + + local topleft, topright, botleft, botright + local corner_chars = vim.g.lazygit_floating_window_corner_chars + if type(corner_chars) == 'table' and #corner_chars == 4 then + topleft, topright, botleft, botright = unpack(corner_chars) + else + topleft, topright, botleft, botright = '╭', '╮', '╰', '╯' + end + + local border_lines = { topleft .. string.rep('─', width) .. topright } + local middle_line = '│' .. string.rep(' ', width) .. '│' + for i = 1, height do + table.insert(border_lines, middle_line) + end + table.insert(border_lines, botleft .. string.rep('─', width) .. botright) + + -- create a unlisted scratch buffer for the border + local border_buffer = api.nvim_create_buf(false, true) + + -- set border_lines in the border buffer from start 0 to end -1 and strict_indexing false + api.nvim_buf_set_lines(border_buffer, 0, -1, true, border_lines) + -- create border window + local border_window = api.nvim_open_win(border_buffer, true, border_opts) + vim.cmd('set winhl=Normal:Floating') + + -- create a unlisted scratch buffer + if LAZYGIT_BUFFER == nil or vim.fn.bufwinnr(LAZYGIT_BUFFER) == -1 then + LAZYGIT_BUFFER = api.nvim_create_buf(false, true) + else + LAZYGIT_LOADED = true + end + -- create file window, enter the window, and use the options defined in opts + local _ = api.nvim_open_win(LAZYGIT_BUFFER, true, opts) + + vim.bo[LAZYGIT_BUFFER].filetype = 'lazygit' + + vim.cmd('setlocal bufhidden=hide') + vim.cmd('setlocal nocursorcolumn') + vim.cmd('set winblend=' .. vim.g.lazygit_floating_window_winblend) + + -- use autocommand to ensure that the border_buffer closes at the same time as the main buffer + local cmd = [[autocmd WinLeave silent! execute 'hide']] + vim.cmd(cmd) + cmd = [[autocmd WinLeave silent! execute 'silent bdelete! %s']] + vim.cmd(cmd:format(border_buffer)) +end + +return { + open_floating_window = open_floating_window, +} diff --git a/lua/telescope/_extensions/lazygit_telescope.lua b/lua/telescope/_extensions/lazygit_telescope.lua index f913e3d..2103a2a 100644 --- a/lua/telescope/_extensions/lazygit_telescope.lua +++ b/lua/telescope/_extensions/lazygit_telescope.lua @@ -3,7 +3,7 @@ local finders = require("telescope.finders") local action_set = require("telescope.actions.set") local action_state = require("telescope.actions.state") local conf = require("telescope.config").values -local lazygit = require("lazygit") +local lazygit_utils = require("lazygit.utils") local function open_lazygit(prompt_buf) @@ -31,7 +31,7 @@ local lazygit_repos = function(opts) } local repos = {} - for _, v in pairs(lazygit.lazygit_visited_git_repos) do + for _, v in pairs(lazygit_utils.lazygit_visited_git_repos) do local index = #repos + 1 -- retrieve git repo name local entry = From a13571d4c1a053a872b55bbc8eb51676d0198368 Mon Sep 17 00:00:00 2001 From: thefux Date: Sun, 6 Mar 2022 17:59:35 +0100 Subject: [PATCH 6/8] update readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c11552e..516cec2 100644 --- a/README.md +++ b/README.md @@ -111,11 +111,16 @@ and the main repo. Though switching between submodules and main repo is not stra that was really and ennoying for me so I though about traking all the repo I visited an I can choose from the list which one I'd like to commit in. +to load the telescope extension you have to add this line to your configuration ``` lua require('telescope').load_extension('lazygit_telescope') ``` -``` lua +by default the paths of each repo is stored only when lazygit is triggered. Though, this may not be convenient, so it possible +to do something like this: +``` vim autocmd BufEnter * :lua require('lazygit.utils').project_root_dir() ``` +that make sure that any opened buffer which have a git repo will be tracked. + From 024dd000f2d5999e8bfc742bd6813c92a3fae4f9 Mon Sep 17 00:00:00 2001 From: thefux Date: Sun, 6 Mar 2022 20:30:29 +0100 Subject: [PATCH 7/8] Update README.md --- README.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 516cec2..3e43506 100644 --- a/README.md +++ b/README.md @@ -95,10 +95,14 @@ If you have `neovim-remote` and don't want `lazygit.nvim` to use it, you can dis let g:lazygit_use_neovim_remote = 0 ``` -###Telescope Plugin +### Telescope Plugin the telescope Plugin is used to track all git repository visited in one nvim session. +![lazygittelplugin](https://user-images.githubusercontent.com/10464534/156933468-c89abee4-6afb-457c-8b02-55b67913aef2.png) +(background image is not included :smirk:) + + __why a telescope Plugin__ ? Assuming you have one or more submodule(s) in your project and you want to commit changes in both the submodule(s) and the main repo. Though switching between submodules and main repo is not strait forward. My solution was at first, @@ -108,19 +112,23 @@ and the main repo. Though switching between submodules and main repo is not stra 4. then open a file in the main repo 5. open lazygit 6. do commit -that was really and ennoying for me -so I though about traking all the repo I visited an I can choose from the list which one I'd like to commit in. +that was really ennoying for me so I though about traking all repo I worked on, then I can choose from the list where I want to commit and open it with lazygit. + +__how to use__ to load the telescope extension you have to add this line to your configuration ``` lua require('telescope').load_extension('lazygit_telescope') ``` -by default the paths of each repo is stored only when lazygit is triggered. Though, this may not be convenient, so it possible -to do something like this: +by default the paths of each repo is stored only when lazygit is triggered. Though, this may not be convenient, so it possible to do something like this: ``` vim autocmd BufEnter * :lua require('lazygit.utils').project_root_dir() ``` -that make sure that any opened buffer which have a git repo will be tracked. +that make sure that any opened buffer which is contained in a git repo will be tracked. +invoke the plugin: +```lua +lua require("telescope").extensions.lazygit_telescope.lazygit() +``` From 7ea7390d5dbfee173e7f4968f68c086b66e12b67 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sun, 6 Mar 2022 13:42:56 -0700 Subject: [PATCH 8/8] docs: Update README.md --- README.md | 33 ++++++++++++------- .../{lazygit_telescope.lua => lazygit.lua} | 0 2 files changed, 21 insertions(+), 12 deletions(-) rename lua/telescope/_extensions/{lazygit_telescope.lua => lazygit.lua} (100%) diff --git a/README.md b/README.md index 3e43506..f42f16e 100644 --- a/README.md +++ b/README.md @@ -97,15 +97,18 @@ let g:lazygit_use_neovim_remote = 0 ### Telescope Plugin -the telescope Plugin is used to track all git repository visited in one nvim session. +The Telescope plugin is used to track all git repository visited in one nvim session. ![lazygittelplugin](https://user-images.githubusercontent.com/10464534/156933468-c89abee4-6afb-457c-8b02-55b67913aef2.png) (background image is not included :smirk:) +**Why a telescope Plugin** ? -__why a telescope Plugin__ ? Assuming you have one or more submodule(s) in your project and you want to commit changes in both the submodule(s) -and the main repo. Though switching between submodules and main repo is not strait forward. My solution was at first, +and the main repo. +Though switching between submodules and main repo is not straight forward. +A solution at first could be: + 1. open a file inside the submodule 2. open lazygit 3. do commit @@ -113,22 +116,28 @@ and the main repo. Though switching between submodules and main repo is not stra 5. open lazygit 6. do commit -that was really ennoying for me so I though about traking all repo I worked on, then I can choose from the list where I want to commit and open it with lazygit. +That is really annoying. +Instead, you can open it with telescope. -__how to use__ -to load the telescope extension you have to add this line to your configuration -``` lua -require('telescope').load_extension('lazygit_telescope') +**How to use** + +To load the telescope extension you have to add this line to your configuration: + +```lua +require('telescope').load_extension('lazygit') ``` -by default the paths of each repo is stored only when lazygit is triggered. Though, this may not be convenient, so it possible to do something like this: -``` vim +By default the paths of each repo is stored only when lazygit is triggered. +Though, this may not be convenient, so it possible to do something like this: + +```vim autocmd BufEnter * :lua require('lazygit.utils').project_root_dir() ``` -that make sure that any opened buffer which is contained in a git repo will be tracked. +That makes sure that any opened buffer which is contained in a git repo will be tracked. + +Once you have loaded the extension, you can invoke the plugin using: -invoke the plugin: ```lua lua require("telescope").extensions.lazygit_telescope.lazygit() ``` diff --git a/lua/telescope/_extensions/lazygit_telescope.lua b/lua/telescope/_extensions/lazygit.lua similarity index 100% rename from lua/telescope/_extensions/lazygit_telescope.lua rename to lua/telescope/_extensions/lazygit.lua