Neovim: Add popup terminal functionality
This commit is contained in:
@@ -6,4 +6,5 @@ require("packages").setup({
|
|||||||
require("development"),
|
require("development"),
|
||||||
require("git"),
|
require("git"),
|
||||||
})
|
})
|
||||||
|
require("terminal").setup()
|
||||||
require("keybinds").setup()
|
require("keybinds").setup()
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
"telescope-recent-files": { "branch": "main", "commit": "eb190c0baded1cbfa9d8767c817b054377683163" },
|
"telescope-recent-files": { "branch": "main", "commit": "eb190c0baded1cbfa9d8767c817b054377683163" },
|
||||||
"telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },
|
"telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },
|
||||||
"todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" },
|
"todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" },
|
||||||
|
"toggleterm.nvim": { "branch": "main", "commit": "9a88eae817ef395952e08650b3283726786fb5fb" },
|
||||||
"trouble.nvim": { "branch": "main", "commit": "85bedb7eb7fa331a2ccbecb9202d8abba64d37b3" },
|
"trouble.nvim": { "branch": "main", "commit": "85bedb7eb7fa331a2ccbecb9202d8abba64d37b3" },
|
||||||
"ultimate-autopair.nvim": { "branch": "development", "commit": "5835876b57901d81ebbeb3cd6ad71aaed66f82d7" },
|
"ultimate-autopair.nvim": { "branch": "development", "commit": "5835876b57901d81ebbeb3cd6ad71aaed66f82d7" },
|
||||||
"vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" },
|
"vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" },
|
||||||
|
|||||||
@@ -3,5 +3,4 @@ require("core.config")
|
|||||||
require("core.buffers")
|
require("core.buffers")
|
||||||
require("core.autocommands")
|
require("core.autocommands")
|
||||||
require("core.globals")
|
require("core.globals")
|
||||||
require("core.commands")
|
|
||||||
require("core.filetypes")
|
require("core.filetypes")
|
||||||
|
|||||||
@@ -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)
|
|
||||||
@@ -1,21 +1,5 @@
|
|||||||
local M = {}
|
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()
|
M.is_buffer_a_file = function()
|
||||||
local buffer_name = vim.fn.bufname()
|
local buffer_name = vim.fn.bufname()
|
||||||
|
|
||||||
@@ -50,6 +34,8 @@ end
|
|||||||
|
|
||||||
M.find_project_root = function()
|
M.find_project_root = function()
|
||||||
local current_directory = M.get_current_directory()
|
local current_directory = M.get_current_directory()
|
||||||
|
if current_directory:match("^term://") then return nil, current_directory end
|
||||||
|
|
||||||
local directory = current_directory
|
local directory = current_directory
|
||||||
while directory ~= "/" and not directory:match("^%a:[/\\]?$") do
|
while directory ~= "/" and not directory:match("^%a:[/\\]?$") do
|
||||||
local git_path = vim.loop.fs_stat(directory .. "/.git")
|
local git_path = vim.loop.fs_stat(directory .. "/.git")
|
||||||
|
|||||||
@@ -223,6 +223,10 @@ M.search_buffer = function()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.toggle_term = function()
|
||||||
|
vim.api.nvim_command("ToggleTerm")
|
||||||
|
end
|
||||||
|
|
||||||
-- TODO: Temporary copy/pasted until project_nvim exposes this function
|
-- TODO: Temporary copy/pasted until project_nvim exposes this function
|
||||||
-- https://github.com/ahmedkhalf/project.nvim/issues/145
|
-- https://github.com/ahmedkhalf/project.nvim/issues/145
|
||||||
-- TODO: Create a Telescope extension out of this, for telescope-all-recent
|
-- TODO: Create a Telescope extension out of this, for telescope-all-recent
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ M.setup = function()
|
|||||||
K("n", "<M-H>", bs.buffer_swap_left)
|
K("n", "<M-H>", bs.buffer_swap_left)
|
||||||
K("n", "<M-L>", bs.buffer_swap_right)
|
K("n", "<M-L>", bs.buffer_swap_right)
|
||||||
|
|
||||||
|
-- Terminal
|
||||||
|
K("n", "<C-\\>", F.toggle_term)
|
||||||
|
K("t", "<C-\\>", F.toggle_term)
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
--- Leader keys ---
|
--- Leader keys ---
|
||||||
|
|
||||||
@@ -253,4 +257,17 @@ M.telescope_default_mappings = function()
|
|||||||
}
|
}
|
||||||
end
|
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
|
return M
|
||||||
|
|||||||
@@ -183,4 +183,26 @@ return {
|
|||||||
opts = {},
|
opts = {},
|
||||||
}, -- :ColorizerToggle
|
}, -- :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,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user