mirror of https://github.com/folke/lazy.nvim.git
feat(util): open terminal commands in a float
This commit is contained in:
parent
7c2eb15444
commit
8ad05feef1
|
@ -16,8 +16,7 @@ end
|
|||
|
||||
function M.open(uri)
|
||||
if M.file_exists(uri) then
|
||||
vim.cmd.split()
|
||||
return vim.cmd.view(uri)
|
||||
return M.float({ win_opts = { style = "" }, file = uri })
|
||||
end
|
||||
local cmd
|
||||
if vim.fn.has("win32") == 1 then
|
||||
|
@ -84,6 +83,38 @@ function M.throttle(ms, fn)
|
|||
end
|
||||
end
|
||||
|
||||
---@param cmd string[]
|
||||
---@param opts? {cwd:string, filetype:string, terminal?:boolean, close_on_exit?:boolean, enter?:boolean}
|
||||
function M.open_cmd(cmd, opts)
|
||||
opts = opts or {}
|
||||
local float = M.float()
|
||||
|
||||
if opts.filetype then
|
||||
vim.bo[float.buf].filetype = opts.filetype
|
||||
end
|
||||
if opts.terminal then
|
||||
opts.terminal = nil
|
||||
vim.fn.termopen(cmd, opts)
|
||||
if opts.enter then
|
||||
vim.cmd.startinsert()
|
||||
end
|
||||
if opts.close_on_exit then
|
||||
vim.api.nvim_create_autocmd("TermClose", {
|
||||
once = true,
|
||||
buffer = float.buf,
|
||||
callback = function()
|
||||
float:close()
|
||||
end,
|
||||
})
|
||||
end
|
||||
else
|
||||
local Process = require("lazy.manage.process")
|
||||
local lines = Process.exec(cmd, { cwd = opts.cwd })
|
||||
vim.api.nvim_buf_set_lines(float.buf, 0, -1, false, lines)
|
||||
vim.bo[float.buf].modifiable = false
|
||||
end
|
||||
end
|
||||
|
||||
---@return string?
|
||||
function M.head(file)
|
||||
local f = io.open(file)
|
||||
|
|
Loading…
Reference in New Issue