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 ++++++++++++++++++++++++++++++++ desktop.conf.yaml | 1 + 2 files changed, 33 insertions(+) create mode 100755 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) diff --git a/desktop.conf.yaml b/desktop.conf.yaml index e7242c2..3176647 100644 --- a/desktop.conf.yaml +++ b/desktop.conf.yaml @@ -10,6 +10,7 @@ ~/.local/bin/randr_output_toggle: bin/randr_output_toggle ~/.local/bin/ssh_sk_clean: bin/ssh_sk_clean ~/.local/bin/udev_match: bin/udev_match + ~/.local/bin/zathura: bin/zathura_wrapper ~/.urxvt/ext/reselect: urxvt/reselect/reselect ~/.xscreensaver: dotfiles/xscreensaver ~/.Xresources: dotfiles/Xresources -- cgit v1.2.3