init.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. local M = {}
  2. M.config = function()
  3. local status_ok, fterm = pcall(require, "FTerm")
  4. if not status_ok then
  5. return
  6. end
  7. fterm.setup(O.plugin.floatterm)
  8. -- Create LazyGit Terminal
  9. local term = require "FTerm.terminal"
  10. local lazy = term:new():setup {
  11. cmd = "lazygit",
  12. dimensions = O.plugin.floatterm.dimensions,
  13. }
  14. local function is_installed(exe)
  15. return vim.fn.executable(exe) == 1
  16. end
  17. -- Use this to toggle gitui in a floating terminal
  18. function _G.__fterm_lazygit()
  19. if is_installed "lazygit" ~= true then
  20. print "Please install lazygit. Check documentation for more information"
  21. return
  22. end
  23. lazy:toggle()
  24. end
  25. -- Map esc to exit inside lazygit
  26. -- vim.api.nvim_exec(
  27. -- [[
  28. -- function LazyGitNativation()
  29. -- echom &filetype
  30. -- if &filetype ==# 'FTerm'
  31. -- tnoremap <Esc> q
  32. -- tnoremap <C-v><Esc> <Esc>
  33. -- endif
  34. -- endfunction
  35. -- ]],
  36. -- false
  37. -- )
  38. O.plugin.which_key.mappings["gg"] = "LazyGit"
  39. vim.api.nvim_set_keymap("n", "<A-i>", "<CMD>lua require('FTerm').toggle()<CR>", { noremap = true, silent = true })
  40. vim.api.nvim_set_keymap("n", "<leader>gg", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true })
  41. vim.api.nvim_set_keymap(
  42. "t",
  43. "<A-i>",
  44. "<C-\\><C-n><CMD>lua require('FTerm').toggle()<CR>",
  45. { noremap = true, silent = true }
  46. )
  47. vim.api.nvim_set_keymap("n", "<A-l>", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true })
  48. vim.api.nvim_set_keymap(
  49. "t",
  50. "<A-l>",
  51. "<C-\\><C-n><CMD>lua _G.__fterm_lazygit()<CR>",
  52. { noremap = true, silent = true }
  53. )
  54. end
  55. return M