Created
November 20, 2016 16:53
-
-
Save b00gizm/66e014395bfc89bb8b70d375beb3c334 to your computer and use it in GitHub Desktop.
Working with Git from iOS (Pythonista + Working Copy)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import OrderedDict | |
import editor | |
import re | |
import sys | |
from urllib.parse import urlencode, quote | |
import webbrowser | |
key = "<YOUR KEY>" | |
def get_path(): | |
regex= r"\/Documents\/(.+)$" | |
path = editor.get_path() | |
matches = re.findall(regex, path) | |
return matches[0] | |
def get_write_url(): | |
params = OrderedDict() | |
params["key"] = key | |
params["x-success"] = "pythonista://" | |
params["repo"] = "Pythonista" | |
params["path"] = get_path() | |
params["text"] = editor.get_text() | |
params["askcommit"] = 1 | |
return "working-copy://x-callback-url/write/?" + urlencode(params, quote_via=quote) | |
def get_read_url(): | |
params = OrderedDict() | |
params["key"] = key | |
params["repo"] = "Pythonista" | |
params["path"] = get_path() | |
params["command"] = "pull" | |
params["command"] = "read" | |
params["x-success"] = "pythonista://update_script?action=run&argv={0}&argv=".format(get_path()) | |
return "working-copy://x-callback-url/chain/?" + urlencode(params, quote_via=quote) | |
def main(): | |
if key == "": | |
print("You need to fill out key with value from Working Copy settings.") | |
quit() | |
url = get_write_url() | |
if len(sys.argv) > 1 and sys.argv[1] == "read": | |
url = get_read_url() | |
webbrowser.open(url) | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import editor | |
import sys | |
def main(): | |
print(sys.argv) | |
if len(sys.argv) <= 1: | |
print("No changes detected.") | |
quit() | |
editor.open_file(sys.argv[1]) | |
text_length = len(editor.get_text()) | |
editor.replace_text(0, text_length, sys.argv[2]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment