diff options
-rwxr-xr-x | bin/zathura_wrapper | 32 | ||||
-rw-r--r-- | desktop.conf.yaml | 1 |
2 files changed, 33 insertions, 0 deletions
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 |