Updated keymaps, not everyone likes lazygit.

This commit is contained in:
Alan-John-Byrne 2024-08-02 18:10:06 +01:00
parent 12818a6cb4
commit 5859d9d914
2 changed files with 25 additions and 3 deletions

View file

@ -130,22 +130,32 @@ if vim.lsp.inlay_hint then
end end
-- lazygit -- lazygit
local status, gitcheck = pcall(require, "lazyvim.util.gitcheck")
if not status then
print("Failed to load gitcheck.")
else
local is_lazygit_available = gitcheck.is_lazygit_available
-- Setting keymaps only if the user has it installed:
if is_lazygit_available() then
map("n", "<leader>gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" }) map("n", "<leader>gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" })
map("n", "<leader>gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" }) map("n", "<leader>gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" })
map("n", "<leader>gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" }) map("n", "<leader>gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" })
map("n", "<leader>gB", LazyVim.lazygit.browse, { desc = "Git Browse" }) map("n", "<leader>gB", LazyVim.lazygit.browse, { desc = "Git Browse" })
map("n", "<leader>gf", function() map("n", "<leader>gf", function()
local git_path = vim.api.nvim_buf_get_name(0) local git_path = vim.api.nvim_buf_get_name(0)
LazyVim.lazygit({args = { "-f", vim.trim(git_path) }}) LazyVim.lazygit({args = { "-f", vim.trim(git_path) }})
end, { desc = "Lazygit Current File History" }) end, { desc = "Lazygit Current File History" })
map("n", "<leader>gl", function() map("n", "<leader>gl", function()
LazyVim.lazygit({ args = { "log" }, cwd = LazyVim.root.git() }) LazyVim.lazygit({ args = { "log" }, cwd = LazyVim.root.git() })
end, { desc = "Lazygit Log" }) end, { desc = "Lazygit Log" })
map("n", "<leader>gL", function() map("n", "<leader>gL", function()
LazyVim.lazygit({ args = { "log" } }) LazyVim.lazygit({ args = { "log" } })
end, { desc = "Lazygit Log (cwd)" }) end, { desc = "Lazygit Log (cwd)" })
else
print("Lazygit is not installed.")
end
end
-- quit -- quit
map("n", "<leader>qq", "<cmd>qa<cr>", { desc = "Quit All" }) map("n", "<leader>qq", "<cmd>qa<cr>", { desc = "Quit All" })

View file

@ -0,0 +1,12 @@
-- Simple check to see if the user has lazygit installed. Only then use keymaps.
gitcheck = {}
function gitcheck.is_lazygit_available()
local handle = io.popen("lazygit --version")
if handle then
local result = handle:read("*a")
handle:close()
return result ~= ""
end
return false
end
return gitcheck