Is it possible to use pure lua to refactor this project?
Opened this issue · 3 comments
neovim have a lua interpreter. If this project can use it to reduce dependency of bash, it will be better?
nvimpager
:
#!/usr/bin/env -S nvim -u NONE -l
-- ...
It is possible to do that but you have to reimplement the command line parsing and some other details that bash offers.
In my opinion that is more work than it is worth. I assume that most systems already have bash installed for some other reason (so I do not consider it a "big" dependency; on my NixOS system for example the full dependency tree of bash is 34MB and the full dependency tree of neovim is 91MB and also includes bash)
Is there any problem with bash as a dependency?
Not all OSs preinstalled bash. Some BSDs installed other shells like ksh as their shell, Some OSs like win even don't have bash. However, in any situation, neovim's lua is accessible.
reimplement the command line parsing
It shouldn't be very complex, just parse vim.v.argv
is OK.
some other details that bash offers
Do you mean [ -t tty ]
?
I meant redirection and environment exports which are more involved with vim functions than with bash. test -t
might be doable in nvim with has('ttyin')
and has('ttyout')
.
If some system does not preinstall bash that is not a problem in my opinion. I suspect most systems do not preinstall neovim either. If a system does not provide bash then you have a point: currently nvimpager is not usable on that system.
Although you Windows is not a priority for me and you can certainly install bash on windows here are some other things that you have to check if and how they can be achieved in lua or on windows:
- the nvimpager script uses
tput
to count the lines in the terminal - the script uses
exec
to start neovim at the end - the script exports environment variables to communicate some values to the nvimpager lua code without shell quoting issues
- the lua code uses nvim_get_proc to detect certain parent processes
I am not motivated to port the bash script to lua but you can try.