#!/usr/bin/python3 # wrapper for zathura that automatically handles HTTP(s) resources, # without needing the monstrosity that is gvfs import contextlib import os import shutil import subprocess import sys import tempfile import urllib.error import urllib.request args = sys.argv[:] with contextlib.ExitStack() as stack: # assume the file is the last argument if (len(args) > 1 and args[-1].startswith('http') and not os.path.exists(args[-1])): tf = stack.enter_context(tempfile.NamedTemporaryFile()) try: resp = urllib.request.urlopen(args[-1]) shutil.copyfileobj(resp, tf) tf.flush() args[-1] = tf.name except urllib.error.URLError as e: sys.stderr.write('Error downloading the URL "%s" to a temporary file\n', str(e)) sys.exit(1) args[0] = '/usr/bin/zathura' subprocess.run(args)