Last active
December 14, 2016 14:01
-
-
Save bennr01/789c0a6e27a0a458f615dc4464c93030 to your computer and use it in GitHub Desktop.
Converts a StaSh (see https://github.com/ywangd/stash/) command to an URL executing the command using the pythonista URL scheme.
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
#!python2 | |
"""encodes a StaSh command to a pythonista3 URL-scheme.""" | |
# If you dont know what StaSh is, check it out: | |
# https://www.github.com/ywangd/stash/ | |
# This script requires a feature which will soon be included in a pull-request | |
# (and hopefully be accepted) | |
import urllib | |
import clipboard | |
def cmd2url(cmd): | |
"""encodes a cmd to an url""" | |
shquoted = '"' + cmd.replace('"', "'") + '"' | |
args = urllib.quote(shquoted, safe="") | |
url = "pythonista3://launch_stash.py?action=run&args=--command%20{a}".format( | |
a=args | |
) | |
return url | |
def main(): | |
"""the main function""" | |
cmd = raw_input("Please enter the StaSh command you want the url for:\n$") | |
url = cmd2url(cmd) | |
print "URL:", url | |
if raw_input("Copy to clipboard (y/n): ").lower() == "y": | |
clipboard.set(url) | |
print "Copied." | |
else: | |
print "Not copied." | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment