Merge pull request #80 from cnrrobertson/LazyGitCurrentFile

Add LazyGitCurrentFile command
This commit is contained in:
Dheepak Krishnamurthy
2022-10-25 16:55:32 -04:00
committed by GitHub
4 changed files with 17 additions and 4 deletions

View File

@@ -37,7 +37,7 @@ let g:lazygit_floating_window_use_plenary = 0 " use plenary.nvim to manage float
let g:lazygit_use_neovim_remote = 1 " fallback to 0 if neovim-remote is not installed let g:lazygit_use_neovim_remote = 1 " fallback to 0 if neovim-remote is not installed
``` ```
Call `:LazyGit` to start a floating window with `lazygit`. Call `:LazyGit` to start a floating window with `lazygit` in the current working directory.
And set up a mapping to call `:LazyGit`: And set up a mapping to call `:LazyGit`:
```vim ```vim
@@ -45,6 +45,8 @@ And set up a mapping to call `:LazyGit`:
nnoremap <silent> <leader>gg :LazyGit<CR> nnoremap <silent> <leader>gg :LazyGit<CR>
``` ```
Call `:LazyGitCurrentFile` to start a floating window with `lazygit` in the project root of the current file.
Open the configuration file for `lazygit` directly from vim. Open the configuration file for `lazygit` directly from vim.
```vim ```vim

View File

@@ -1,5 +1,6 @@
local open_floating_window = require"lazygit.window".open_floating_window local open_floating_window = require"lazygit.window".open_floating_window
local project_root_dir = require"lazygit.utils".project_root_dir local project_root_dir = require"lazygit.utils".project_root_dir
local get_root = require"lazygit.utils".get_root
local is_lazygit_available = require"lazygit.utils".is_lazygit_available local is_lazygit_available = require"lazygit.utils".is_lazygit_available
local is_symlink = require"lazygit.utils".is_symlink local is_symlink = require"lazygit.utils".is_symlink
@@ -67,6 +68,13 @@ local function lazygit(path)
exec_lazygit_command(cmd) exec_lazygit_command(cmd)
end end
--- :LazyGitCurrentFile entry point
local function lazygitcurrentfile()
local current_dir = vim.fn.expand('%:p:h')
local git_root = get_root(current_dir)
lazygit(git_root)
end
--- :LazyGitFilter entry point --- :LazyGitFilter entry point
local function lazygitfilter(path) local function lazygitfilter(path)
if is_lazygit_available() ~= true then if is_lazygit_available() ~= true then
@@ -120,6 +128,7 @@ end
return { return {
lazygit = lazygit, lazygit = lazygit,
lazygitcurrentfile = lazygitcurrentfile,
lazygitfilter = lazygitfilter, lazygitfilter = lazygitfilter,
lazygitfiltercurrentfile = lazygitfiltercurrentfile, lazygitfiltercurrentfile = lazygitfiltercurrentfile,
lazygitconfig = lazygitconfig, lazygitconfig = lazygitconfig,

View File

@@ -25,8 +25,7 @@ local function trim(str)
end end
local function get_root() local function get_root(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
return fn.system('git rev-parse --show-toplevel') return fn.system('git rev-parse --show-toplevel')
@@ -55,7 +54,8 @@ local function project_root_dir()
vim.o.shell = 'bash' vim.o.shell = 'bash'
end end
local root = get_root() local cwd = vim.loop.cwd()
local root = get_root(cwd)
if root == nil then if root == nil then
return nil return nil
end end

View File

@@ -25,6 +25,8 @@ endif
command! LazyGit lua require'lazygit'.lazygit() command! LazyGit lua require'lazygit'.lazygit()
command! LazyGitCurrentFile lua require'lazygit'.lazygitcurrentfile()
command! LazyGitFilter lua require'lazygit'.lazygitfilter() command! LazyGitFilter lua require'lazygit'.lazygitfilter()
command! LazyGitFilterCurrentFile lua require'lazygit'.lazygitfiltercurrentfile() command! LazyGitFilterCurrentFile lua require'lazygit'.lazygitfiltercurrentfile()