From ec74c2d18f236c3ba115e0d7959eaeffbf8a83cf Mon Sep 17 00:00:00 2001 From: kalmenn Date: Thu, 19 Sep 2024 23:21:34 +0200 Subject: [PATCH] feat(overseer): Add templates for compiling and watching typst files --- lua/overseer/template/typst/compile.lua | 22 +++++++++++++++++++ lua/overseer/template/typst/watch.lua | 29 +++++++++++++++++++++++++ lua/plugins/overseer.lua | 25 ++++++++++++--------- 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 lua/overseer/template/typst/compile.lua create mode 100644 lua/overseer/template/typst/watch.lua diff --git a/lua/overseer/template/typst/compile.lua b/lua/overseer/template/typst/compile.lua new file mode 100644 index 0000000..345fe06 --- /dev/null +++ b/lua/overseer/template/typst/compile.lua @@ -0,0 +1,22 @@ +local overseer = require("overseer") + +return { + name = "Compile typst", + builder = function() + local file = vim.fn.expand("%:p") + local cwd = vim.fn.getcwd() + + return { + name = "Compile " .. vim.fn.bufname(), + cmd = { "typst" }, + args = { "compile", file, "--root", cwd }, + } + end, + tags = {overseer.TAG.BUILD}, + condition = { + filetype = { "typst" }, + callback = function() + return vim.fn.executable("typst") == 1 + end, + }, +} diff --git a/lua/overseer/template/typst/watch.lua b/lua/overseer/template/typst/watch.lua new file mode 100644 index 0000000..30acedc --- /dev/null +++ b/lua/overseer/template/typst/watch.lua @@ -0,0 +1,29 @@ +return { + name = "Watch typst", + params = { + pdf_viewer = { + type = "string", + optional = false, + default = "xdg-open", + validate = function(value) + return vim.fn.executable(value) ~= 0 + end, + }, + }, + builder = function(params) + local file = vim.fn.expand("%:p") + local cwd = vim.fn.getcwd() + + return { + name = "Watch " .. vim.fn.bufname(), + cmd = { "typst" }, + args = { "watch", file, "--root", cwd, "--open", params.pdf_viewer }, + } + end, + condition = { + filetype = { "typst" }, + callback = function() + return vim.fn.executable("typst") == 1 + end, + }, +} diff --git a/lua/plugins/overseer.lua b/lua/plugins/overseer.lua index c186180..99e3864 100644 --- a/lua/plugins/overseer.lua +++ b/lua/plugins/overseer.lua @@ -1,12 +1,17 @@ return { - 'stevearc/overseer.nvim', - opts = {}, - keys = { - {"ot", "OverseerToggle", desc = "Toggle Overseer"}, - {"or", "OverseerRun", desc = "Start an Overseer task"}, - {"os", "OverseerRunCmd", desc = "Run a shell command with Overseer"}, - {"ob", "OverseerBuild", desc = "Open the Overseer task builder"}, - {"oo", "OverseerOpen", desc = "Open a window with the output of an Overseer task"}, - {"oa", "OverseerTaskAction", desc = "Add an action to an Overseer task"}, - }, + 'stevearc/overseer.nvim', + opts = { + templates = { + "typst.watch", + "typst.compile", + }, + }, + keys = { + {"ot", "OverseerToggle", desc = "Toggle Overseer"}, + {"or", "OverseerRun", desc = "Start an Overseer task"}, + {"os", "OverseerRunCmd", desc = "Run a shell command with Overseer"}, + {"ob", "OverseerBuild", desc = "Open the Overseer task builder"}, + {"oo", "OverseerOpen", desc = "Open a window with the output of an Overseer task"}, + {"oa", "OverseerTaskAction", desc = "Add an action to an Overseer task"}, + }, }