From e4ac5c4ebcd52b4492916660673040d5a9612235 Mon Sep 17 00:00:00 2001 From: "Gustavo \"Guz\" L de Mello" Date: Wed, 10 Dec 2025 19:07:38 -0300 Subject: [PATCH] feat(commands): grip command for markdown preview --- lua/dot/commands.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++ lua/dot/init.lua | 1 + 2 files changed, 51 insertions(+) create mode 100644 lua/dot/commands.lua diff --git a/lua/dot/commands.lua b/lua/dot/commands.lua new file mode 100644 index 0000000..269ef16 --- /dev/null +++ b/lua/dot/commands.lua @@ -0,0 +1,50 @@ +-- Grip markdown reader + +---@type integer? +local grip_channel = nil +vim.api.nvim_create_user_command("GripStart", function() + if grip_channel then + return + end + + local file = vim.api.nvim_buf_get_name(0) + local cmd = "go-grip -b false -H 0.0.0.0 " .. file + + grip_channel = vim.fn.jobstart(cmd, { + on_stderr = function(_, err) + if grip_channel == nil then + return + end + + vim.fn.jobstop(grip_channel) + + local content = table.concat(err, "\n") + if #content > 0 then + vim.notify("Grip error: " .. content, vim.log.levels.ERROR, {}) + end + end, + on_exit = function() + if grip_channel == nil then + return + end + + vim.fn.chanclose(grip_channel) + grip_channel = nil + end, + stderr_buffered = true, + }) +end, {}) + +vim.api.nvim_create_user_command("GripStop", function() + if grip_channel then + vim.fn.jobstop(grip_channel) + end +end, {}) + +vim.api.nvim_create_autocmd({ "QuitPre", "BufDelete" }, { + callback = function() + if grip_channel then + vim.fn.jobstop(grip_channel) + end + end, +}) diff --git a/lua/dot/init.lua b/lua/dot/init.lua index abefb00..d8b0e80 100644 --- a/lua/dot/init.lua +++ b/lua/dot/init.lua @@ -87,6 +87,7 @@ vim.diagnostic.config({ }, }) +require("dot.commands") require("dot.keymaps") require("nvim-treesitter.configs").setup({