if vim.g.loaded_shell then return end vim.g.loaded_shell = true vim.api.nvim_create_user_command("Shell", function(opts) opts.args = vim.trim(opts.args) if #opts.args == 0 then return vim.notify("shell cmd empty", vim.log.levels.WARN) end local cmdmsg = { { "command " }, { opts.args, "@markup.raw" } } local pg = { source = "shell", title = "shell cmd", kind = "progress", percent = 0, status = "running", } table.insert(cmdmsg, { " started" }) pg.id = vim.api.nvim_echo(cmdmsg, true, pg) vim.system({ vim.o.shell, vim.o.shellcmdflag, opts.args }, {}, function(o) pg.percent = 100 if not o.code or o.code ~= 0 then pg.status = "failed" cmdmsg[3] = { (" exited with code %d SIG%d"):format(o.code, o.signal) } vim.schedule(function() vim.api.nvim_echo(cmdmsg, true, pg) end) else pg.status = "success" cmdmsg[3] = { (" exited succesfully"):format(o.code, o.signal) } vim.schedule(function() vim.api.nvim_echo(cmdmsg, true, pg) end) end end) end, { nargs = "*", complete = "shellcmd", desc = "run shell command", })