floatterm.lua 1.8 KB

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