Browse Source

Neovim: Add popup terminal functionality

wayland
Riyyi 18 hours ago
parent
commit
935d6d999b
  1. 1
      .config/nvim/init.lua
  2. 1
      .config/nvim/lazy-lock.json
  3. 1
      .config/nvim/lua/core.lua
  4. 18
      .config/nvim/lua/core/commands.lua
  5. 18
      .config/nvim/lua/core/functions.lua
  6. 4
      .config/nvim/lua/keybind-functions.lua
  7. 17
      .config/nvim/lua/keybinds.lua
  8. 22
      .config/nvim/lua/ui.lua

1
.config/nvim/init.lua

@ -6,4 +6,5 @@ require("packages").setup({
require("development"),
require("git"),
})
require("terminal").setup()
require("keybinds").setup()

1
.config/nvim/lazy-lock.json

@ -35,6 +35,7 @@
"telescope-recent-files": { "branch": "main", "commit": "eb190c0baded1cbfa9d8767c817b054377683163" },
"telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },
"todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" },
"toggleterm.nvim": { "branch": "main", "commit": "9a88eae817ef395952e08650b3283726786fb5fb" },
"trouble.nvim": { "branch": "main", "commit": "85bedb7eb7fa331a2ccbecb9202d8abba64d37b3" },
"ultimate-autopair.nvim": { "branch": "development", "commit": "5835876b57901d81ebbeb3cd6ad71aaed66f82d7" },
"vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" },

1
.config/nvim/lua/core.lua

@ -3,5 +3,4 @@ require("core.config")
require("core.buffers")
require("core.autocommands")
require("core.globals")
require("core.commands")
require("core.filetypes")

18
.config/nvim/lua/core/commands.lua

@ -1,18 +0,0 @@
local F = require("core.functions")
local create_command = function(name, command)
if not name or type(name) ~= "string" then return end
vim.api.nvim_create_user_command(name, function()
local cmd = type(command) == "function" and command() or command
F.execute_command(cmd)
end, {})
end
create_command("RunScript", "ls")
create_command("ScanScript", function()
local file_path = vim.fn.expand("%:p")
LOG(file_path)
return "ls"
end)

18
.config/nvim/lua/core/functions.lua

@ -1,21 +1,5 @@
local M = {}
M.execute_command = function(command)
if not command then return end
local job = require("plenary.job")
job:new({
command = command,
on_exit = function(j, _)
vim.schedule(function()
vim.api.nvim_echo({
{ table.concat(j:result(), "\n"), "Normal" }
}, false, {})
end)
end,
}):start()
end
M.is_buffer_a_file = function()
local buffer_name = vim.fn.bufname()
@ -50,6 +34,8 @@ end
M.find_project_root = function()
local current_directory = M.get_current_directory()
if current_directory:match("^term://") then return nil, current_directory end
local directory = current_directory
while directory ~= "/" and not directory:match("^%a:[/\\]?$") do
local git_path = vim.loop.fs_stat(directory .. "/.git")

4
.config/nvim/lua/keybind-functions.lua

@ -223,6 +223,10 @@ M.search_buffer = function()
})
end
M.toggle_term = function()
vim.api.nvim_command("ToggleTerm")
end
-- TODO: Temporary copy/pasted until project_nvim exposes this function
-- https://github.com/ahmedkhalf/project.nvim/issues/145
-- TODO: Create a Telescope extension out of this, for telescope-all-recent

17
.config/nvim/lua/keybinds.lua

@ -66,6 +66,10 @@ M.setup = function()
K("n", "<M-H>", bs.buffer_swap_left)
K("n", "<M-L>", bs.buffer_swap_right)
-- Terminal
K("n", "<C-\\>", F.toggle_term)
K("t", "<C-\\>", F.toggle_term)
----------------------------------------
--- Leader keys ---
@ -253,4 +257,17 @@ M.telescope_default_mappings = function()
}
end
-- Keybindings for toggleterm.nvim
M.toggleterm_nvim = function()
local keymaps = function()
local opts = { buffer = 0 }
K("t", "<Esc>", [[<C-\><C-n>]], opts)
end
vim.api.nvim_create_autocmd("TermOpen", {
pattern = "term://*toggleterm#*",
callback = keymaps,
})
end
return M

22
.config/nvim/lua/ui.lua

@ -183,4 +183,26 @@ return {
opts = {},
}, -- :ColorizerToggle
-- Popup terminal
{
"akinsho/toggleterm.nvim",
config = function()
require("toggleterm").setup({
auto_scroll = true,
direction = "float",
float_opts = {
border = "curved",
row = function() return vim.o.lines - 4 end,
width = function() return vim.o.columns - 6 end,
height = 20,
winblend = 0,
},
hide_numbers = true,
open_mapping = nil,
persist_mode = true,
size = 20,
start_in_insert = true,
})
end,
}
}

Loading…
Cancel
Save