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

Execute commands (e.g. compile files) from iVim, locally. #23

Open
wants to merge 94 commits into
base: master
Choose a base branch
from

Conversation

holzschu
Copy link

@holzschu holzschu commented Nov 9, 2017

The idea is, while you're editing a file, you might want to run an external tool on it (python, lua, latex...)
This used to be impossible on iOS. With this modification, when you hit ":make" in Vim (or ), it calls OpenURL with the specific scheme "blinkshell://" and transfers the command to blinkshell (another app, see here: https://github.com/blinksh/blink ) who then executes the command. The URL looks like: "blinkshell://command%20flags%20name_of_the_file".

This only works if the file is inside the blinkshell sandbox, and has been "opened-in-place" (an iOS 11 fonctionnality). I extract the original name and position of the file from its mirrorURL, so blinkshell acts on the original file.

Obviously, direct commands such as "!ls" and "!pwd" also work, but again only inside blinkshell sandbox.

@holzschu
Copy link
Author

Separate functionality added: when a function calls "system(rmdir /path/to/directory)" or "system(rm /path/to/file)", execute these calls locally using standard lib calls to rmdir() and removefile().

This is really useful when using netrw: the file explorer shows files, lets us edit them... but not delete directories. Also temporary directories created when editing are not always removed when the app crashes. This lets us clean up the working area ourselves.

It is a separate addition from the previous one. They can be merged separately if needed. Their only common point is "#define USE_SYSTEM".

@terrychou
Copy link
Owner

Here are some of my thoughts concerning the external command part:

  1. If I understand it right, blinkshell is a terminal app connecting to remote hosts via ssh or mosh. It doesn't really have a shell itself. And I see this method is heavily based on passing commands to it via the "blinkshell://" URL scheme.

  2. If this is the case. First, it is kind of confusing. In vim, users invoke local shell commands via the "!" way (such as :!ls). They are expecting those commands to work on the environment in which vim is situated. (e.g. :!ls to list the files right under the current working directory.) However, if we pass the commands to blink, they will be invoked on the remote host blink is connecting to. So, it would be another totally different environment.

  3. Secondly, it is sort of depending. It depends on the external app Blink. What if a user doesn't have it installed? And what if the URL scheme is changed some day?

  4. I tried to run some commands such as :!ls and :!pwd. They didn't work for me. (no results feedback)

  5. I see it uses mirrorURL. But I think its role maybe misunderstood: the mirror URL is for iVim managing resources 'open-in-place'd in other apps.

@holzschu
Copy link
Author

I understand your issues. They all come from sandbox limitations: an app can only work on apps inside its sandbox. Open-in-place is a small workaround, but it only applies to opening the file, and to the file itself (the permission does not extend to its directory, so there's no way to access other files, or create a file).

If I understand you, you would prefer to have the commands inside the iVim binary, working on the files inside the iVim sandbox. I can do that too (I did for rmdir, for example).

inside its sandbox. Especially useful with rmdir (not available
otherwise) and gunzip (edit gzipped files in place)
@holzschu
Copy link
Author

Here is a revised attempt. All commands are now executed inside of iVim's sandbox. The commands currently available are: ls touch rm cp ln link mv mkdir rmdir chown chgrp chflags chmod du df chksum sum stat readlink compress uncompress gzip gunzip.

Of these, the ones that I found really useful are:

  • rmdir, because the tmp directory tends to get crowded with directories that vim doesn't know how to remove (because vim calls the system for rmdir, but not for rm). In netrw, typing "D" calls rmdir on the directory. As with the system rmdir, it only works if the directory is empty.
  • gzip/gunzip, because (with autocmd) it allows vim to edit gzipped files, and gzip the modified file after writing. I think there is a vim plugin for that.

The other commands are mostly available as a proof of concept. You will need the file_cmds_ios framework, from my port of blinkshell (https://github.com/holzschu/blink , in the AppleSource/file_cmds-264.50.1 directory ). I haven't found how to share the source between the two github repositories, sorry.

@sedm0784
Copy link

sedm0784 commented Nov 20, 2017

I've only skimmed most of the above and don't know github's UI all that well, so apologies if this has already been discussed or even addressed in commits, but the change to the entitlements file doesn't look right to me, and there seem to be some whitespace-only changes to vim/src/os_unix.c which seem like a bad idea with regards to any potential future merges with/updates from the main Vim codebase.

@holzschu
Copy link
Author

I reverted the entitlement file, and cancelled the whitespace-only changes.

@holzschu holzschu changed the title Execute commands (e.g. compile files) from iVim by calling blinkshell Execute commands (e.g. compile files) from iVim, locally. Nov 20, 2017
@kkebo
Copy link

kkebo commented Apr 27, 2019

@terrychou What is the current status?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants