[
:h requester-introduction][help-requester-introduction]
requester.nvim is a simple plugin to execute a shell command under your cursor.
the output is displayed in a new window.
jq is strongly recommended. In order to query json results, jq is required.
Install using your plugin manager of choice.
-- lazy.nvim example
{
"calebbray/requester.nvim",
opts = {
--- @param input string
--- @return { error: string?, output: string, type: string? }
executor = function(input)
-- handler for executing commands
-- executor must accept a string
-- executor must return output as a string
-- executor may return an error string
-- executor may return the output type of the command (for preview buffer syntax highlighting)
end
}
}Right now, requester.nvim assumes output is going to be in json format, but it's not required.
You may use jq query syntax to filter/query json output.
{
--- @param input string
--- @return { error: string?, output: string, type: string? }
executor = function(input)
local out = ""
local result = vim.system({ "zsh", "-c", input }):wait()
if result.code ~= 0 then
local message = format_shell_error(result.stdout)
return { error = message, output = out, type = "text" }
end
-- if there is output sent to stderr we are going to capture it for now
-- This might not be a great pattern but I know I use it for some things
if #result.stderr > 0 then
out = out .. result.stderr .. "\n"
end
out = out .. vim.trim(result.stdout)
return { output = out, type = detect_format(result.stdout) }
end
}