From feb9fa61ae0c0473da3b6ce77c1bbeaae7b44193 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Nov 2021 11:24:27 +0100 Subject: desktop: add a wrapper for zathura handling HTTP(s) URLs Zathura can do it by itself, but that requires gvfs, which is a giant gnome monster I do not want to install for such a simple thing. --- bin/zathura_wrapper | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 bin/zathura_wrapper (limited to 'bin/zathura_wrapper') diff --git a/bin/zathura_wrapper b/bin/zathura_wrapper new file mode 100755 index 0000000..0129df3 --- /dev/null +++ b/bin/zathura_wrapper @@ -0,0 +1,32 @@ +#!/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) + args[-1] = tf.name + except urllib.error.URLError as e: + sys.stderr.write('Error downloading the URL "%s" to a temporary file', str(e)) + sys.exit(1) + + args[0] = '/usr/bin/zathura' + + subprocess.run(args) -- cgit v1.2.3