ソースを参照

Replace LazyGit Plugin with FTerm Instance (#717)

* Replace LazyGit Plugin with FTerm Instance

* Added  gg keybind to FTerm LazyGit

* Added check to see if lazygit is installed

* Changed lazyload event to prevent error when called from dashboard on startup

* Removed lazygit plugin.  Changed Fterm lazy loading

* Made the executable check more universal for when we include other terminal applications

Co-authored-by: rebuilt <memoryman51@hotmail.com>
Jonathan Raines 4 年 前
コミット
f6e377fcfe
4 ファイル変更47 行追加15 行削除
  1. 0 1
      lua/default-config.lua
  2. 39 0
      lua/lv-floatterm/init.lua
  3. 6 2
      lua/lv-which-key/init.lua
  4. 2 12
      lua/plugins.lua

+ 0 - 1
lua/default-config.lua

@@ -78,7 +78,6 @@ O = {
     symbol_outline = { active = false },
     debug = { active = false },
     dap_install = { active = false },
-    lazygit = { active = false },
     lush = { active = false },
     diffview = { active = false },
     floatterm = { active = false },

+ 39 - 0
lua/lv-floatterm/init.lua

@@ -0,0 +1,39 @@
+local M = {}
+
+M.config = function()
+    require'FTerm'.setup({
+        dimensions  = {
+            height = 0.8,
+            width = 0.8,
+            x = 0.5,
+            y = 0.5
+        },
+        border = 'single' -- or 'double'
+    })
+
+    -- Create LazyGit Terminal
+    local term = require("FTerm.terminal")
+    local lazy = term:new():setup({
+        cmd = "lazygit",
+        dimensions = {
+            height = 0.9,
+            width = 0.9
+        }
+    })
+
+    local function is_installed(exe)
+        return vim.fn.executable(exe) == 1
+    end
+
+     -- Use this to toggle gitui in a floating terminal
+    function _G.__fterm_lazygit()
+        if is_installed("lazygit") ~= true then
+            print("Please install lazygit. Check documentation for more information")
+            return
+        end
+        lazy:toggle()
+    end
+end
+
+return M
+

+ 6 - 2
lua/lv-which-key/init.lua

@@ -263,8 +263,12 @@ if O.plugin.zen.active then
   vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>", { noremap = true, silent = true })
   mappings["z"] = "Zen"
 end
-if O.plugin.lazygit.active then
-  vim.api.nvim_set_keymap("n", "<leader>gg", ":LazyGit<CR>", { noremap = true, silent = true })
+if O.plugin.floatterm.active then
+  vim.api.nvim_set_keymap("n", "<leader>gg", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true })
+  vim.api.nvim_set_keymap("n", "<A-i>", "<CMD>lua require('FTerm').toggle()<CR>", { noremap = true, silent = true })
+  vim.api.nvim_set_keymap("t", "<A-i>", "<C-\\><C-n><CMD>lua require('FTerm').toggle()<CR>", { noremap = true, silent = true })
+  vim.api.nvim_set_keymap("n", "<A-l>", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true })
+  vim.api.nvim_set_keymap("t", "<A-l>", "<C-\\><C-n><CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true })
   mappings["gg"] = "LazyGit"
 end
 if O.plugin.telescope_project.active then

+ 2 - 12
lua/plugins.lua

@@ -217,12 +217,9 @@ return require("packer").startup(function(use)
   -- Floating terminal
   use {
     "numToStr/FTerm.nvim",
-    event = "BufRead",
+    event = "BufWinEnter",
     config = function()
-      require("FTerm").setup {
-        dimensions = { height = 0.8, width = 0.8, x = 0.5, y = 0.5 },
-        border = "single", -- or 'double'
-      }
+        require('lv-floatterm').config()
     end,
     disable = not O.plugin.floatterm.active,
   }
@@ -249,13 +246,6 @@ return require("packer").startup(function(use)
     disable = not O.plugin.sanegx.active,
   }
 
-  -- Lazygit
-  use {
-    "kdheepak/lazygit.nvim",
-    cmd = "LazyGit",
-    disable = not O.plugin.lazygit.active,
-  }
-
   -- Diffview
   use {
     "sindrets/diffview.nvim",