terminal.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. local M = {}
  2. M.config = function()
  3. lvim.builtin["terminal"] = {
  4. -- size can be a number or function which is passed the current terminal
  5. size = 5,
  6. -- open_mapping = [[<c-\>]],
  7. open_mapping = [[<c-t>]],
  8. hide_numbers = true, -- hide the number column in toggleterm buffers
  9. shade_filetypes = {},
  10. shade_terminals = true,
  11. shading_factor = 2, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light
  12. start_in_insert = true,
  13. insert_mappings = true, -- whether or not the open mapping applies in insert mode
  14. persist_size = true,
  15. -- direction = 'vertical' | 'horizontal' | 'window' | 'float',
  16. direction = "float",
  17. close_on_exit = true, -- close the terminal window when the process exits
  18. shell = vim.o.shell, -- change the default shell
  19. -- This field is only relevant if direction is set to 'float'
  20. float_opts = {
  21. -- The border key is *almost* the same as 'nvim_win_open'
  22. -- see :h nvim_win_open for details on borders however
  23. -- the 'curved' border is a custom border type
  24. -- not natively supported but implemented in this plugin.
  25. -- border = 'single' | 'double' | 'shadow' | 'curved' | ... other options supported by win open
  26. border = "curved",
  27. -- width = <value>,
  28. -- height = <value>,
  29. winblend = 3,
  30. highlights = {
  31. border = "Normal",
  32. background = "Normal",
  33. },
  34. },
  35. }
  36. end
  37. M.setup = function()
  38. local status_ok, terminal = pcall(require, "toggleterm")
  39. if not status_ok then
  40. print(terminal)
  41. return
  42. end
  43. vim.api.nvim_set_keymap(
  44. "n",
  45. "<leader>gg",
  46. "<cmd>lua require('core.terminal')._lazygit_toggle()<CR>",
  47. { noremap = true, silent = true }
  48. )
  49. lvim.builtin.which_key.mappings["gg"] = "LazyGit"
  50. terminal.setup(lvim.builtin.terminal)
  51. end
  52. local function is_installed(exe)
  53. return vim.fn.executable(exe) == 1
  54. end
  55. M._lazygit_toggle = function()
  56. if is_installed "lazygit" ~= true then
  57. print "Please install lazygit. Check documentation for more information"
  58. return
  59. end
  60. local Terminal = require("toggleterm.terminal").Terminal
  61. local lazygit = Terminal:new { cmd = "lazygit", hidden = true }
  62. lazygit:toggle()
  63. end
  64. return M