From 2423fcdc904ec1413edaaac1fd8b9c0971f4a869 Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Mon, 12 Jul 2021 21:11:43 -0400 Subject: refactor single file --- lua/core/floatterm.lua | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 lua/core/floatterm.lua (limited to 'lua/core/floatterm.lua') diff --git a/lua/core/floatterm.lua b/lua/core/floatterm.lua new file mode 100644 index 00000000..3d7e0e6e --- /dev/null +++ b/lua/core/floatterm.lua @@ -0,0 +1,76 @@ +local M = {} +M.config = function() + O.plugin.floatterm = { + active = false, + dimensions = { + height = 0.9, + width = 0.9, + x = 0.5, + y = 0.3, + }, + border = "single", -- or 'double' + } +end + +M.setup = function() + local status_ok, fterm = pcall(require, "FTerm") + if not status_ok then + return + end + + fterm.setup(O.plugin.floatterm) + + -- Create LazyGit Terminal + local term = require "FTerm.terminal" + local lazy = term:new():setup { + cmd = "lazygit", + dimensions = O.plugin.floatterm.dimensions, + } + + 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 + + -- Map esc to exit inside lazygit + -- vim.api.nvim_exec( + -- [[ + -- function LazyGitNativation() + -- echom &filetype + -- if &filetype ==# 'FTerm' + -- tnoremap q + -- tnoremap + -- endif + -- endfunction + -- ]], + -- false + -- ) + + O.plugin.which_key.mappings["gg"] = "LazyGit" + vim.api.nvim_set_keymap("n", "", "lua require('FTerm').toggle()", { noremap = true, silent = true }) + vim.api.nvim_set_keymap("n", "gg", "lua _G.__fterm_lazygit()", { noremap = true, silent = true }) + + vim.api.nvim_set_keymap( + "t", + "", + "lua require('FTerm').toggle()", + { noremap = true, silent = true } + ) + vim.api.nvim_set_keymap("n", "", "lua _G.__fterm_lazygit()", { noremap = true, silent = true }) + vim.api.nvim_set_keymap( + "t", + "", + "lua _G.__fterm_lazygit()", + { noremap = true, silent = true } + ) +end + +return M -- cgit v1.2.3