Created
May 17, 2024 23:55
-
-
Save melMass/1847645763b7bc55859fa8a26a500e8f to your computer and use it in GitHub Desktop.
Very crude nu overlay provider for overseer.nvim. It doesn't take arguments so only works on nu defs that don't have args. It only looks for env.nu at the root of the project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local overseer = require('overseer') | |
local nushell = require('mtb.nushell') | |
local mtb_shell = require('mtb.utils.shell') | |
---@type overseer.TemplateFileDefinition | |
local tmpl = { | |
name = 'nushell', | |
priority = 60, | |
params = { | |
name = { type = 'string', optional = true, default = 'no name' }, | |
cmd = { type = 'string' }, | |
args = { optional = true, type = 'list', delimiter = ' ' }, | |
cwd = { optional = true }, | |
}, | |
builder = function(params) | |
return { | |
name = params.name, | |
cmd = { params.cmd }, | |
args = params.args, | |
cwd = params.cwd, | |
-- NOTE: echo.notify is an overseer component similar to the builtin notify | |
-- but for echo.nvim, a plugin to add audio to neovim. | |
-- this requires my plugin echo: https://github.com/melMass/echo.nvim | |
-- components = { { 'unique', replace = true }, { 'echo.notify' }, 'default' }, | |
} | |
end, | |
} | |
return { | |
condition = { | |
callback = function(params) | |
local env = vim.fn.filereadable('env.nu') | |
return env ~= 0 | |
end, | |
}, | |
-- this is run once or whenever the cache_key changes | |
generator = function(search, cb) | |
local lines, err = mtb_shell.execute('overlay use env.nu;scope modules | last | get commands | get name| to text') | |
local overlay_cmds = {} | |
if not lines then | |
print('Error:', err) | |
else | |
for _, line in ipairs(lines) do | |
table.insert(overlay_cmds, line) | |
end | |
end | |
local ret = {} | |
for _, cmd in ipairs(overlay_cmds) do | |
table.insert( | |
ret, | |
overseer.wrap_template(tmpl, { name = cmd }, { name = cmd, cmd = 'nu', args = { nushell.custom_configs, "-c 'overlay use env.nu;" .. cmd .. "'" } }) | |
) | |
end | |
cb(ret) | |
end, | |
cache_key = function(opts) | |
return vim.fn.getcwd() .. '/env.nu' | |
end, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment