Assume we have the following lua function to create a non-file backed buffer:
M.makeScratch = function(scratchpath)
local uri = vim.uri_from_fname(scratchpath)
local bufnr = vim.uri_to_bufnr(uri)
vim.bo[bufnr].bufhidden = ""
vim.bo[bufnr].buflisted = true
vim.bo[bufnr].buftype = "nofile"
vim.bo[bufnr].readonly = false
vim.bo[bufnr].swapfile = false
end
Now assume there is shell opened and the uri + buffer number is known (can be found via scratch path).
How can I pipe a command output to the created scratch buffer (not backed by a file)?
I don’t have a complete answer, but I’d use the client-server feature of Neovim to pass the --listen option to the Neovim instance that creates a buffer, then run a command to pipe stdin to the server.
I wold run ZQ after seing what i were looking for, discarding the buffer completelly
but you gave me an idea, a zsh autoloaded function
nvscratch() {
local content
if [[ -p /dev/stdin ]]; then
content=$(cat -) # receives a pipi
else
content="$("$@")" # run with argument
fi
nvim -c "enew | setlocal buftype=nofile bufhidden=wipe noswapfile" +"0read !echo \"$content\""
}