summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-11-22 11:24:27 +0100
committerAnton Khirnov <anton@khirnov.net>2021-11-22 11:24:27 +0100
commitfeb9fa61ae0c0473da3b6ce77c1bbeaae7b44193 (patch)
treef751a8fc84b529c05bf4767b624b6dccfc9bdfa8
parent4573d659a936e47980ac99bd53d4d627d3ab3f15 (diff)
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.
-rwxr-xr-xbin/zathura_wrapper32
-rw-r--r--desktop.conf.yaml1
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