init.lua 1.6 KB

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