diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index a6f1c574..bda99f9e 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -122,7 +122,7 @@ LazyVim.toggle.map("uw", LazyVim.toggle("wrap", { name = "Wrap" })) LazyVim.toggle.map("uL", LazyVim.toggle("relativenumber", { name = "Relative Number" })) LazyVim.toggle.map("ud", LazyVim.toggle.diagnostics) LazyVim.toggle.map("ul", LazyVim.toggle.number) -LazyVim.toggle.map( "uc", LazyVim.toggle("conceallevel", { values = { 0, vim.o.conceallevel > 0 and vim.o.conceallevel or 2 } })) +LazyVim.toggle.map("uc", LazyVim.toggle("conceallevel", { values = { 0, vim.o.conceallevel > 0 and vim.o.conceallevel or 2 } })) LazyVim.toggle.map("uT", LazyVim.toggle.treesitter) LazyVim.toggle.map("ub", LazyVim.toggle("background", { values = { "light", "dark" }, name = "Background" })) if vim.lsp.inlay_hint then @@ -130,22 +130,32 @@ if vim.lsp.inlay_hint then end -- 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", "gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" }) map("n", "gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" }) map("n", "gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" }) map("n", "gB", LazyVim.lazygit.browse, { desc = "Git Browse" }) - map("n", "gf", function() local git_path = vim.api.nvim_buf_get_name(0) LazyVim.lazygit({args = { "-f", vim.trim(git_path) }}) end, { desc = "Lazygit Current File History" }) - map("n", "gl", function() LazyVim.lazygit({ args = { "log" }, cwd = LazyVim.root.git() }) end, { desc = "Lazygit Log" }) map("n", "gL", function() LazyVim.lazygit({ args = { "log" } }) end, { desc = "Lazygit Log (cwd)" }) +else + print("Lazygit is not installed.") +end +end + -- quit map("n", "qq", "qa", { desc = "Quit All" }) diff --git a/lua/lazyvim/util/gitcheck.lua b/lua/lazyvim/util/gitcheck.lua new file mode 100644 index 00000000..fae563ff --- /dev/null +++ b/lua/lazyvim/util/gitcheck.lua @@ -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 \ No newline at end of file