Files
watchexec.nvim/lua/watchexec/init.lua
T

68 lines
1.7 KiB
Lua
Raw Normal View History

---@brief [[
--- watchexec.nvim integrates the watchexec CLI into Neovim, providing a
--- floating or split window to display file-watching command output.
---@brief ]]
local config = require("watchexec.config")
local runner = require("watchexec.runner")
local window = require("watchexec.window")
local indicator = require("watchexec.indicator")
2026-07-04 08:46:05 -05:00
local M = {}
---Merge user-provided options into the config and resolve the watchexec binary.
---Call this in your init.lua: `require("watchexec").setup({...})`.
---@param opts? watchexec.Config
2026-07-04 08:46:05 -05:00
function M.setup(opts)
config.setup(opts)
2026-07-04 08:46:05 -05:00
end
---Start a watchexec process for the given command.
---Stops any previously running process, opens the output window if hidden,
---then spawns the child process.
---@param command string Shell command to run under watchexec
function M.run(command)
if runner.is_running() then
runner.stop()
end
window.clear()
if not window.is_visible() then
window.open()
end
runner.start(command)
indicator.refresh()
end
---Stop the currently running watchexec process.
function M.stop()
runner.stop()
window.clear()
indicator.reset()
indicator.refresh()
end
---Toggle the watchexec output window.
---If no process is running and window is hidden, opens with a placeholder.
---If no process is running and window is visible, closes it.
---If running and visible, hides the window.
---If running but hidden, shows the window.
function M.toggle()
if not runner.is_running() then
if window.is_visible() then
window.close()
else
window.clear()
window.open()
end
elseif window.is_visible() then
window.toggle()
else
window.open()
end
2026-07-04 08:46:05 -05:00
end
return M