terrychou / iVim

A vim port to iOS.
598 stars 35 forks source link

Integrating more command line tools #95

Open andyxukq opened 4 years ago

andyxukq commented 4 years ago

Love the built-in terminal (aka ivish), it opens lots of potential to extend use case scenarios of ivim. I have two questions regarding bringing more functionalities to the built-in terminal:

  1. Could you help point to related code base or setting that makes adding more command line tools possible? For example, how did you add the command “python3”, “pip” or “ssh”?
  2. Adding git command would be a great improvement to local development workflow since it eliminates the needs of third part apps like “Working Copy”. I’ve been thinking of adding it myself if that’s not already on your roadmap. I’d also like to ask you if there’s anything in particular stopped you from doing it, like technical restrictions?

Thanks!

terrychou commented 4 years ago

Glad to know that you like iVim's internal terminal and ivish.

To answer your questions, I think I need to make some concepts clear first.

A normal command line tool is written in the traditional process-way, which means that they will be spawn into processes when start running in the host systems. However, for the sake of security, iOS forbids apps to start any new processes on their own. As a workaround, Nicolas Holzschuch's project https://github.com/holzschu/ios_system provides a way utilizing threading to simulate a process environment. With specific modifications of the code to adapt this environment, most command line tools will work.

However, due to the essential differences between processes and threads, there are still some hurdles not easy to overcome:

  1. Signals

Process-spawn systems use signals to communicate with the running code, largely. But the way signals are handled in threading prevents ios_system to deal with them perfectly.

  1. environment variables

Unlike processes, which each has one copy of its own environment variables, threads share one copy of environment variables. As a result, it is often tricky to manipulate environment variables in ios_system.

Now are my answers to your questions:

  1. For the understanding of the working of iVim's external commands, you can refer to the ios_system project. In it, it provides the source code of the whole simulation idea. Moreover, Nicolas also generously provides some tools that he has been adapting for ios_system, and instructions in details to do the adaption. You can also have a look at my modification of the tool catimg: https://github.com/terrychou/catimg_ios .

  2. As to git, I have been considering adding it to iVim too. However, even though it is open source, its code base looks a bit of complicated to adapt ios_system. There is a third party library called libgit2 (https://github.com/libgit2/libgit2) offering git's functions, it doesn't provide the exact command line interface as git, though. Since iVim provides python scripting support, another approach could be to use some python implementation of git, like the dulwich package. With all above said, if you want to give it a try to adapt the git code base, please do and it would be wonderful. If you have any other good ideas, please do share.

andyxukq commented 4 years ago

Thanks for taking time to answer my questions and much appreciate your detailed explanation.

Because of the limitations you mentioned, there must be tons of cross-platform patches to be done in order to bind UNIX programs to iOS eco, and that's what makes projects including yours so valuable :D

I see that the latest version of iVim (built with ivish) isn't on Github yet. I was wondering if you could shed some light on how you implemented the interactive shell (terminal)? The shell comes with iVim is very high quality.

terrychou commented 4 years ago

I have pushed up the latest code of iVim and the code of ivish (https://github.com/terrychou/ivish), you can check them out.

andyxukq commented 4 years ago

Thanks! Checking them out.

idvorkin commented 3 years ago

@terrychou Woah -- I haven't used iVIM in a while, this new terminal is incredible (as is plug support, and iex support - wow!).

I agree, git is the critical missing command. Just tried dulwich but looks like it needs to compile stuff. Would it make sense to create a new issue for just git support?

Would it make sense to make a bounty for the git feature? I'm guessing it's a boon for all apps using ios_system, and folks would be willing to donate!