New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(lua): add vim.system()
#23827
feat(lua): add vim.system()
#23827
Conversation
3c81b0f
to
878caf5
Compare
vim.system()
603c8d0
to
7060ffe
Compare
Is there a way to pipe stuff to |
Yes, |
49c8942
to
9831ec0
Compare
I don't think For now, I think we just need to make the tests handle outputs with |
That is a strong argument (also since it's easier to strip than to restore). Is this something that should/could be mentioned somewhere, or is this too niche or obvious in the context? |
Is this low-hanging fruit now, or better left for a follow-up PR? neovim/runtime/lua/provider/health.lua Lines 78 to 141 in 0370e4d
|
I would say it is just hanging fruit. I did have a go at refactoring it but the code has some niche options that I'm not sure are meaningful to keep. And tbh, the whole file could do with some cleanup so probably better to do it in one go (in a follow up PR). |
|
0194751
to
a4dfcca
Compare
For the Note
Lua can happily handle embedded So now the following are roughly equivalent. local out = vim.fn.system({'echo', 'hello'})
local out = vim.system({'echo', 'hello'}, {text=true}):wait().stdout
|
7509ddd
to
b920c36
Compare
7b1a6b8
to
f9be445
Compare
Problem: Handling system commands in Lua is tedious and error-prone: - vim.fn.jobstart() is vimscript and comes with all limitations attached to typval. - vim.loop.spawn is too low level Solution: Add vim.system(). Partly inspired by Python's subprocess module Does not expose any libuv objects.
The message seems like it's indicating |
@lewis6991 it does though, tested on CMD and PS, isn't echo a native command lol ? EDIT: you are right though fd seems to return something but not echo, I'm very confused :) |
The tests added in this PR cover echo on windows so the issue must be something specific to your environment. |
@lewis6991 didn't work on my second desktop but worked on my laptop, so yeah it's probably something on my side, do these commands all run on default CMD ? |
No idea, |
(And please stop using this PR as support forum. You're notifying all reviewers. Use matrix if you've general usage questions. ) |
Problem
Handling system commands in Lua is tedious and error-prone:
vim.fn.jobstart()
is vimscript and comes with all limitations attached to typval.vim.loop.spawn
is too low levelAlso see: #17620 (comment)
Solution
Add
vim.system()
.Todo
Future work
/dev/null
support. (Can pass an empty handler for the same effect)