diff options
| author | Barlingo <[email protected]> | 2021-07-26 15:27:36 -0400 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-26 15:27:36 -0400 | 
| commit | 273fdedf32987913c7281181dcc0d85f005cc81b (patch) | |
| tree | 54badf36f08ba53592bf598b90da2554487457f7 | |
| parent | 4d68c6eb78bc1376be5e7fb5c3303001eb425228 (diff) | |
run stylua (#1122)
Co-authored-by: Diego Barranco <[email protected]>
| -rw-r--r-- | lua/core/terminal.lua | 45 | 
1 files changed, 34 insertions, 11 deletions
| diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 81287c94..015341df 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -32,6 +32,11 @@ M.config = function()          background = "Normal",        },      }, +    -- Add executables on the lv-config file +    -- { exec, keymap, name} +    -- lvim.builtin.terminal.execs = {{}} to overwrite +    -- lvim.builtin.terminal.execs[#lvim.builtin.terminal.execs+1] = {"gdb", "tg", "GNU Debugger"} +    execs = { { "lazygit", "gg", "LazyGit" } },    }  end @@ -41,28 +46,46 @@ M.setup = function()      print(terminal)      return    end +  for _, exec in pairs(lvim.builtin.terminal.execs) do +    require("core.terminal").add_exec(exec[1], exec[2], exec[3]) +  end +  terminal.setup(lvim.builtin.terminal) +end + +local function is_installed(exe) +  return vim.fn.executable(exe) == 1 +end + +M.add_exec = function(exec, keymap, name)    vim.api.nvim_set_keymap(      "n", -    "<leader>gg", -    "<cmd>lua require('core.terminal')._lazygit_toggle()<CR>", +    "<leader>" .. keymap, +    "<cmd>lua require('core.terminal')._exec_toggle('" .. exec .. "')<CR>",      { noremap = true, silent = true }    ) -  lvim.builtin.which_key.mappings["gg"] = "LazyGit" -  terminal.setup(lvim.builtin.terminal) +  lvim.builtin.which_key.mappings[keymap] = name  end -local function is_installed(exe) -  return vim.fn.executable(exe) == 1 +M._split = function(inputstr, sep) +  if sep == nil then +    sep = "%s" +  end +  local t = {} +  for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do +    table.insert(t, str) +  end +  return t  end -M._lazygit_toggle = function() -  if is_installed "lazygit" ~= true then -    print "Please install lazygit. Check documentation for more information" +M._exec_toggle = function(exec) +  local binary = M._split(exec)[1] +  if is_installed(binary) ~= true then +    print("Please install executable " .. binary .. ". Check documentation for more information")      return    end    local Terminal = require("toggleterm.terminal").Terminal -  local lazygit = Terminal:new { cmd = "lazygit", hidden = true } -  lazygit:toggle() +  local exec_term = Terminal:new { cmd = exec, hidden = true } +  exec_term:toggle()  end  return M | 
