summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-10-16 13:41:27 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-10-16 13:44:30 (GMT)
commitda73cf1541ee7c0f67e80f5089bc60992417b634 (patch)
tree1796871aed325acc44e2e734a70ed8e4e0156ea0
parentae50c9c7282346ada12b95dfbda03faecc656370 (diff)
downloadeeshow-da73cf1541ee7c0f67e80f5089bc60992417b634.zip
eeshow-da73cf1541ee7c0f67e80f5089bc60992417b634.tar.gz
eeshow-da73cf1541ee7c0f67e80f5089bc60992417b634.tar.bz2
eeshow-viewer: caching wrapper for document viewers
-rw-r--r--Makefile2
-rwxr-xr-xeeshow-viewer67
2 files changed, 68 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index cb47d1f..605152d 100644
--- a/Makefile
+++ b/Makefile
@@ -225,7 +225,7 @@ leak: eediff
#----- Install / uninstall ---------------------------------------------------
-install: eeshow eeplot eediff
+install: eeshow eeplot eediff eeshow-viewer
mkdir -p $(DESTDIR)/$(PREFIX)/bin/
install -m 755 $^ $(DESTDIR)/$(PREFIX)/bin/
diff --git a/eeshow-viewer b/eeshow-viewer
new file mode 100755
index 0000000..e28908e
--- /dev/null
+++ b/eeshow-viewer
@@ -0,0 +1,67 @@
+#!/bin/sh
+# eeshow-viewer - Caching wrapper for document viewers
+#
+# Written 2016 by Werner Almesberger
+# Copyright 2016 by Werner Almesberger
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+
+#
+# Known issues:
+# - should only cache things we can expect to be able to properly use locally,
+# e.g., PDF, text, etc., not Web pages
+#
+
+default_dir=$HOME/.eeshow-viewer-cache
+
+
+usage()
+{
+ cat <<EOF 1>&2
+usage: $0 [-c] [-m] [URL]
+
+ -c cache only, without starting a viewer
+ -m create the cache directory (default: $default_dir)
+EOF
+ exit 1
+}
+
+
+make_cache=false
+cache_only=false
+while [ "$1" ]; do
+ case "$1" in
+ -c) cache_only=true;;
+ -m) make_cache=true;;
+ -*) usage;;
+ *) break;;
+ esac
+ shift
+done
+
+dir=${EESHOW_VIEWER_CACHE:-$default_dir}
+
+if [ ! -d "$dir" ]; then
+ if $make_cache; then
+ mkdir -p "$dir" || exit 1
+ else
+ echo "no cache directory \"$dir\"" 1>&2
+ echo "run eeshow-viewer -m to create" 1>&2
+ exit 1
+ fi
+fi
+
+[ "$1" ] || exit 0
+
+hash=`echo -n "$1" | tr -c '[[:alnum:].\-]' _`
+file=$dir/$hash
+if [ ! -r "$file" ]; then
+ wget -O "$file" "$1" || exit 1
+fi
+
+$cache_only && exit
+${EESHOW_VIEWER_VIEWER:-xdg-open} "$file"