robin/laufey

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

Justin M. KeyesMerge #18706 execute Lua with "nvim -l"08ebf8d3a8

master
690 B35 linesraw
1-- Test "nvim -l foo.lua …"
2
3local function printbufs()
4  local bufs = ''
5  for _, v in ipairs(vim.api.nvim_list_bufs()) do
6    local b = vim.fn.bufname(v)
7    if b:len() > 0 then
8      bufs = ('%s %s'):format(bufs, b)
9    end
10  end
11  print(('bufs:%s'):format(bufs))
12end
13
14local function parseargs(args)
15  local exitcode = nil
16  for i = 1, #args do
17    if args[i] == '--exitcode' then
18      exitcode = tonumber(args[i + 1])
19    end
20  end
21  return exitcode
22end
23
24local function main()
25  printbufs()
26  print('nvim args:', #vim.v.argv)
27  print('lua args:', vim.inspect(_G.arg))
28
29  local exitcode = parseargs(_G.arg)
30  if type(exitcode) == 'number' then
31    os.exit(exitcode)
32  end
33end
34
35main()