Skip to content

Instantly share code, notes, and snippets.

@giodamelio
Created October 20, 2015 20:53
Show Gist options
  • Save giodamelio/4185781d2a36a600555e to your computer and use it in GitHub Desktop.
Save giodamelio/4185781d2a36a600555e to your computer and use it in GitHub Desktop.
A simple Terminator plugin to allow quick opening of IPFS/IPNS hashes
from urlparse import urljoin
import terminatorlib.plugin as plugin
NAME = "IPFSURLHandler"
# Make terminator recognize plugin
AVAILABLE = [NAME]
available = AVAILABLE # For old versions of terminator
SETTINGS = {
"gatewayURL": "https://ipfs.io/",
}
class IPFSURLHandler(plugin.URLHandler):
"""Open IPFS and IPNS urls on a gateway"""
capabilities = ["url_handler"]
handler_name = "ipfs_handler"
match = "(/ip[fn]s/)?Qm[a-zA-Z0-9]{44}"
nameopen = "Open on Gateway"
namecopy = "Copy Gateway URL"
def callback(self, url):
if url.startswith("/ipfs/"):
return urljoin(SETTINGS["gatewayURL"], url)
elif url.startswith("/ipns/"):
return urljoin(SETTINGS["gatewayURL"], url)
else:
return urljoin(SETTINGS["gatewayURL"], "/ipfs/" + url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment