Skip to content
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

Is it possible to use pure lua to refactor this project? #94

Open
Freed-Wu opened this issue Feb 19, 2024 · 3 comments
Open

Is it possible to use pure lua to refactor this project? #94

Freed-Wu opened this issue Feb 19, 2024 · 3 comments
Labels
help wanted waiting waiting for a reply or more info

Comments

@Freed-Wu
Copy link

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
-- ...
@lucc
Copy link
Owner

lucc commented Feb 20, 2024

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?

@lucc lucc added the waiting waiting for a reply or more info label Feb 20, 2024
@Freed-Wu
Copy link
Author

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 ]?

@lucc
Copy link
Owner

lucc commented Feb 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted waiting waiting for a reply or more info
Projects
None yet
Development

No branches or pull requests

2 participants