clean up and add some ducumentation
This commit is contained in:
25
README.md
25
README.md
@@ -94,3 +94,28 @@ If you have `neovim-remote` and don't want `lazygit.nvim` to use it, you can dis
|
|||||||
```vim
|
```vim
|
||||||
let g:lazygit_use_neovim_remote = 0
|
let g:lazygit_use_neovim_remote = 0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
###Telescope Plugin
|
||||||
|
|
||||||
|
the telescope Plugin is used to track all git repository visited in one nvim session.
|
||||||
|
|
||||||
|
__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,
|
||||||
|
1. open a file inside the submodule
|
||||||
|
2. open lazygit
|
||||||
|
3. do commit
|
||||||
|
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.
|
||||||
|
|
||||||
|
``` lua
|
||||||
|
require('telescope').load_extension('lazygit_telescope')
|
||||||
|
```
|
||||||
|
|
||||||
|
``` lua
|
||||||
|
autocmd BufEnter * :lua require('lazygit.utils').project_root_dir()
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -9,25 +9,17 @@ LAZYGIT_BUFFER = nil
|
|||||||
LAZYGIT_LOADED = false
|
LAZYGIT_LOADED = false
|
||||||
vim.g.lazygit_opened = 0
|
vim.g.lazygit_opened = 0
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
-- 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
|
--- on_exit callback function to delete the open buffer when lazygit exits in a neovim terminal
|
||||||
local function on_exit(job_id, code, event)
|
local function on_exit(job_id, code, event)
|
||||||
if code ~= 0 then
|
if code ~= 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
clean_up_after_exit()
|
vim.cmd('silent! :q')
|
||||||
|
LAZYGIT_BUFFER = nil
|
||||||
|
LAZYGIT_LOADED = false
|
||||||
|
vim.g.lazygit_opened = 0
|
||||||
|
vim.cmd('silent! :checktime')
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Call lazygit
|
--- Call lazygit
|
||||||
|
|||||||
@@ -5,17 +5,17 @@ local lazygit_visited_git_repos = {}
|
|||||||
|
|
||||||
-- TODO:check if the repo isa git repo
|
-- TODO:check if the repo isa git repo
|
||||||
local function append_git_repo_path(repo_path)
|
local function append_git_repo_path(repo_path)
|
||||||
if repo_path == nil or not fn.isdirectory(repo_path) then
|
if repo_path == nil or not fn.isdirectory(repo_path) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, path in ipairs(lazygit_visited_git_repos) do
|
for _, path in ipairs(lazygit_visited_git_repos) do
|
||||||
if path == repo_path then
|
if path == repo_path then
|
||||||
return
|
return
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(lazygit_visited_git_repos, tostring(repo_path))
|
table.insert(lazygit_visited_git_repos, tostring(repo_path))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -26,25 +26,25 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local function get_root()
|
local function get_root()
|
||||||
local cwd = vim.loop.cwd()
|
local cwd = vim.loop.cwd()
|
||||||
local status, job = pcall(require, 'plenary.job')
|
local status, job = pcall(require, 'plenary.job')
|
||||||
if not status then
|
if not status then
|
||||||
local gitdir = fn.system('git rev-parse --show-toplevel')
|
return fn.system('git rev-parse --show-toplevel')
|
||||||
end
|
end
|
||||||
|
|
||||||
local gitroot_job = job:new({
|
local gitroot_job = job:new({
|
||||||
'git',
|
'git',
|
||||||
'rev-parse',
|
'rev-parse',
|
||||||
'--show-toplevel',
|
'--show-toplevel',
|
||||||
cwd=cwd
|
cwd=cwd
|
||||||
})
|
})
|
||||||
|
|
||||||
local _, code = gitroot_job:sync()
|
local path, code = gitroot_job:sync()
|
||||||
if (code ~= 0) then
|
if (code ~= 0) then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return fn.getcwd(0, 0)
|
return table.concat(path, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get project_root_dir for git repository
|
--- Get project_root_dir for git repository
|
||||||
@@ -52,13 +52,17 @@ local function project_root_dir()
|
|||||||
-- always use bash on Unix based systems.
|
-- always use bash on Unix based systems.
|
||||||
local oldshell = vim.o.shell
|
local oldshell = vim.o.shell
|
||||||
if vim.fn.has('win32') == 0 then
|
if vim.fn.has('win32') == 0 then
|
||||||
vim.o.shell = 'bash'
|
vim.o.shell = 'bash'
|
||||||
end
|
end
|
||||||
|
|
||||||
local root = get_root()
|
local root = get_root()
|
||||||
|
if root == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd = string.format('cd "%s" && git rev-parse --show-toplevel', fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h'), root)
|
||||||
-- try symlinked file location instead
|
-- try symlinked file location instead
|
||||||
local gitdir = fn.system(
|
local gitdir = fn.system(cmd)
|
||||||
'cd "' .. fn.fnamemodify(fn.resolve(fn.expand('%:p')), ':h') .. '" && git rev-parse --show-toplevel')
|
|
||||||
local isgitdir = fn.matchstr(gitdir, '^fatal:.*') == ''
|
local isgitdir = fn.matchstr(gitdir, '^fatal:.*') == ''
|
||||||
|
|
||||||
if isgitdir then
|
if isgitdir then
|
||||||
@@ -89,9 +93,9 @@ end
|
|||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get_root = get_root,
|
get_root = get_root,
|
||||||
project_root_dir = project_root_dir,
|
project_root_dir = project_root_dir,
|
||||||
lazygit_visited_git_repos = lazygit_visited_git_repos,
|
lazygit_visited_git_repos = lazygit_visited_git_repos,
|
||||||
is_lazygit_available = is_lazygit_available,
|
is_lazygit_available = is_lazygit_available,
|
||||||
is_symlink = is_symlink,
|
is_symlink = is_symlink,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ local lazygit_utils = require("lazygit.utils")
|
|||||||
|
|
||||||
local function open_lazygit(prompt_buf)
|
local function open_lazygit(prompt_buf)
|
||||||
local entry = action_state.get_selected_entry()
|
local entry = action_state.get_selected_entry()
|
||||||
local cmd = [[lua require"lazygit".lazygit(nil)]]
|
|
||||||
cmd = cmd:format(entry.value:gsub("%s", ""))
|
|
||||||
|
|
||||||
vim.fn.execute('cd ' .. entry.value)
|
vim.fn.execute('cd ' .. entry.value)
|
||||||
|
|
||||||
|
local cmd = [[lua require"lazygit".lazygit(nil)]]
|
||||||
vim.api.nvim_command(cmd)
|
vim.api.nvim_command(cmd)
|
||||||
|
|
||||||
vim.cmd('stopinsert')
|
vim.cmd('stopinsert')
|
||||||
vim.cmd([[execute "normal i"]])
|
vim.cmd([[execute "normal i"]])
|
||||||
|
vim.fn.feedkeys('j')
|
||||||
vim.api.nvim_buf_set_keymap(0, 't', '<Esc>', '<Esc>', {noremap = true, silent = true})
|
vim.api.nvim_buf_set_keymap(0, 't', '<Esc>', '<Esc>', {noremap = true, silent = true})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -32,16 +33,22 @@ local lazygit_repos = function(opts)
|
|||||||
|
|
||||||
local repos = {}
|
local repos = {}
|
||||||
for _, v in pairs(lazygit_utils.lazygit_visited_git_repos) do
|
for _, v in pairs(lazygit_utils.lazygit_visited_git_repos) do
|
||||||
|
if v == nil then
|
||||||
|
goto skip
|
||||||
|
end
|
||||||
|
|
||||||
local index = #repos + 1
|
local index = #repos + 1
|
||||||
-- retrieve git repo name
|
|
||||||
local entry =
|
local entry =
|
||||||
{
|
{
|
||||||
idx = index,
|
idx = index,
|
||||||
value = v:gsub("%s", ""),
|
value = v:gsub("%s", ""),
|
||||||
|
-- retrieve git repo name
|
||||||
repo_name= v:gsub("%s", ""):match("^.+/(.+)$"),
|
repo_name= v:gsub("%s", ""):match("^.+/(.+)$"),
|
||||||
}
|
}
|
||||||
|
|
||||||
table.insert(repos, index, entry)
|
table.insert(repos, index, entry)
|
||||||
|
|
||||||
|
::skip::
|
||||||
end
|
end
|
||||||
|
|
||||||
pickers.new(opts or {}, {
|
pickers.new(opts or {}, {
|
||||||
|
|||||||
Reference in New Issue
Block a user