robin/ivy

my custom neovim config

git clone https://git.robinwobin.dev/robin/ivy

robinplugin: fix `:Shell` progress & lint11251ed

main
1.1 KiB44 linesraw
1if vim.g.loaded_shell then
2  return
3end
4
5vim.g.loaded_shell = true
6
7vim.api.nvim_create_user_command("Shell", function(opts)
8  opts.args = vim.trim(opts.args)
9  if #opts.args == 0 then
10    return vim.notify("shell cmd empty", vim.log.levels.WARN)
11  end
12
13  ---@type [string,(string|integer)?][]
14  local cmdmsg = { { "command " }, { opts.args, "@markup.raw" } }
15
16  local pg = {
17    source = "shell",
18    title = "shell cmd",
19    kind = "progress",
20    status = "running",
21  }
22  table.insert(cmdmsg, { " started" })
23  pg.id = vim.api.nvim_echo(cmdmsg, true, pg)
24
25  vim.system({ vim.o.shell, vim.o.shellcmdflag, opts.args }, {}, function(o)
26    if not o.code or o.code ~= 0 then
27      pg.status = "failed"
28      cmdmsg[3] = { (" exited with code %d SIG%d"):format(o.code, o.signal) }
29      vim.schedule(function()
30        vim.api.nvim_echo(cmdmsg, true, pg)
31      end)
32    else
33      pg.status = "success"
34      cmdmsg[3] = { (" exited succesfully"):format(o.code, o.signal) }
35      vim.schedule(function()
36        vim.api.nvim_echo(cmdmsg, true, pg)
37      end)
38    end
39  end)
40end, {
41  nargs = "*",
42  complete = "shellcmd",
43  desc = "run shell command",
44})