feat: implement public API and plugin commands

Rewrite init.lua to expose setup(), run(), stop(), and toggle() that
coordinate across config, runner, window, and indicator modules. Replace
the placeholder SayHello command in plugin/watchexec.lua with keymaps
(<Leader>wx{t,s,r}), :WatchexecRun/:WatchexecStop/:WatchexecToggle
commands, VimLeavePre cleanup, and VimResized auto-resize.
This commit is contained in:
Stevan Freeborn
2026-07-06 19:51:37 -05:00
parent 398d3dd585
commit 1c46c3fcd9
5 changed files with 417 additions and 22 deletions
+57 -2
View File
@@ -1,9 +1,64 @@
---@type boolean|nil
if vim.g.loaded_watchexec then
return
end
vim.g.loaded_watchexec = 1
vim.api.nvim_create_user_command("SayHello", function()
require("watchexec").say_hello()
vim.keymap.set("n", "<Leader>wxt", function()
require("watchexec").toggle()
end, { desc = "Toggle watchexec window" })
vim.keymap.set("n", "<Leader>wxs", function()
require("watchexec").stop()
end, { desc = "Stop watchexec" })
vim.keymap.set("n", "<Leader>wxr", function()
local cmd = vim.fn.input("Watchexec: ")
if cmd and #cmd > 0 then
require("watchexec").run(cmd)
end
end, { desc = "Run watchexec with prompt" })
vim.api.nvim_create_user_command("WatchexecRun", function(opts)
require("watchexec").run(opts.args)
end, { nargs = 1, complete = "file" })
vim.api.nvim_create_user_command("WatchexecStop", function()
require("watchexec").stop()
end, {})
vim.api.nvim_create_user_command("WatchexecToggle", function()
require("watchexec").toggle()
end, {})
vim.api.nvim_set_hl(0, "WatchexecSuccess", { bg = "#00ff00", default = true })
vim.api.nvim_set_hl(0, "WatchexecFailure", { bg = "#ff0000", default = true })
vim.api.nvim_create_augroup("watchexec_nvim", { clear = true })
vim.api.nvim_create_autocmd("VimLeavePre", {
group = "watchexec_nvim",
callback = function()
require("watchexec.runner").stop()
end,
})
---@type table|nil
local resize_timer
vim.api.nvim_create_autocmd("VimResized", {
group = "watchexec_nvim",
callback = function()
if resize_timer then
resize_timer:close()
end
resize_timer = vim.defer_fn(function()
resize_timer = nil
require("watchexec.window").resize_float()
require("watchexec.indicator").reposition()
end, 100)
end,
})