Split out personal modules.

This commit is contained in:
2026-08-06 06:26:21 +02:00
parent e8275c583d
commit e9556df285
3 changed files with 131 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
-- ------------------------------------------------------------
-- BUILD SYSTEM
-- ------------------------------------------------------------
local function build(args)
if vim.fn.filereadable("build.sh") == 0 then
vim.notify("No build.sh found in current directory.", vim.log.levels.WARN)
return
end
vim.cmd("wall")
local command = "./build.sh"
if #args > 0 then
command = command .. " " .. table.concat(args, " ")
end
send("clear && " .. command)
end
vim.api.nvim_create_user_command(
"Build",
function(opts) build(opts.fargs) end,
{
nargs = "*",
desc = "Run project build.sh",
}
)
map("n", "<C-Space>", function() build({}) end, { desc = "Build project", })
map("t", "<C-Space>", function() build({}) end, { desc = "Build project", })
+11
View File
@@ -0,0 +1,11 @@
-- ------------------------------------------------------------
-- LSP
local capabilities = require("blink.cmp").get_lsp_capabilities()
vim.lsp.config("gopls", { capabilities = capabilities, })
vim.lsp.config("ols", { capabilities = capabilities, })
vim.lsp.enable({ "gopls", "ols", })
map("n", "gd", vim.lsp.buf.definition)
map("i", "<C-h>", vim.lsp.buf.signature_help)
vim.api.nvim_create_user_command("Rename", function() vim.lsp.buf.rename() end, {})
vim.api.nvim_create_user_command("Actions", function() vim.lsp.buf.code_action() end, {})
+90
View File
@@ -0,0 +1,90 @@
-- ------------------------------------------------------------
-- TERMINAL SYSTEM
-- ------------------------------------------------------------
local term_buf = nil
local function open_term_split()
vim.cmd("botright vsplit")
local win = vim.api.nvim_get_current_win()
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
vim.api.nvim_win_set_buf(win, term_buf)
else
vim.cmd("terminal")
term_buf = vim.api.nvim_get_current_buf()
end
vim.api.nvim_win_set_width(win, math.floor(vim.o.columns * 0.37))
vim.cmd("startinsert")
end
local function toggle_term()
for _, win in ipairs(vim.api.nvim_list_wins()) do
if vim.api.nvim_win_get_buf(win) == term_buf then
vim.api.nvim_win_close(win, false)
return
end
end
open_term_split()
end
local function open_term_fullscreen()
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
vim.api.nvim_set_current_buf(term_buf)
else
vim.cmd("terminal")
term_buf = vim.api.nvim_get_current_buf()
end
vim.cmd("startinsert")
end
local function prev_non_term_buf()
local current = vim.api.nvim_get_current_buf()
local buffers = vim.fn.getbufinfo({ buflisted = 1 })
local candidates = {}
for _, buffer in ipairs(buffers) do
if buffer.bufnr ~= current and vim.bo[buffer.bufnr].buftype ~= "terminal" then
table.insert(candidates, buffer)
end
end
if #candidates == 0 then
print("No previous non-terminal buffer")
return
end
table.sort(candidates, function(a, b)
return a.lastused > b.lastused
end)
vim.api.nvim_set_current_buf(candidates[1].bufnr)
end
function send(command)
local terminal_visible = false
for _, win in ipairs(vim.api.nvim_list_wins()) do
if term_buf and vim.api.nvim_win_get_buf(win) == term_buf then
terminal_visible = true
break
end
end
if not terminal_visible then
open_term_split()
end
local job = vim.b[term_buf].terminal_job_id
if job then
vim.api.nvim_chan_send(job, command .. "\n")
end
end
map("n", "<C-j>", toggle_term, { desc = "Toggle terminal split", })
map("n", "<C-o>", open_term_fullscreen, { desc = "Open terminal fullscreen", })
map("t", "<C-j>", toggle_term, { desc = "Toggle terminal split", })
map("t", "<C-o>", prev_non_term_buf, { desc = "Return to previous buffer", })