summaryrefslogtreecommitdiff
path: root/lib/qutebrowser-exec
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2018-01-04 13:48:22 -0200
committerSilvio Rhatto <rhatto@riseup.net>2018-01-04 13:48:22 -0200
commit63fb51fa5737f99dd69f122bdac5493d3360008b (patch)
tree0dbb837f0bac61405e1f3352aad51e479da4dca9 /lib/qutebrowser-exec
parentbf6014f52e34b0e4181039592877039acb80b6df (diff)
downloadqutebrowser-63fb51fa5737f99dd69f122bdac5493d3360008b.tar.gz
qutebrowser-63fb51fa5737f99dd69f122bdac5493d3360008b.tar.bz2
Updates dist, adds qutebrowser-exec for session handling
Diffstat (limited to 'lib/qutebrowser-exec')
-rwxr-xr-xlib/qutebrowser-exec79
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/qutebrowser-exec b/lib/qutebrowser-exec
new file mode 100755
index 0000000..7c5c119
--- /dev/null
+++ b/lib/qutebrowser-exec
@@ -0,0 +1,79 @@
+#!/usr/bin/env sh
+#
+# Thanks https://github.com/ayekat/dotfiles/blob/master/bin/qutebrowser
+# Adapted to be sourced from another wrapper
+
+# Wrapper around qutebrowser that makes sessions (-r, --restore SESSION) behave
+# like they used to in dwb.
+#
+# We do so by filtering out the -r/--restore option passed to qutebrowser and
+# using the argument to set up the following directory structure and symbolic
+# links:
+#
+# $XDG_RUNTIME_DIR/qutebrowser/$session/cache → $XDG_CACHE_HOME/qutebrowser/$session
+# $XDG_RUNTIME_DIR/qutebrowser/$session/data → $XDG_DATA_HOME/qutebrowser/$session
+# $XDG_RUNTIME_DIR/qutebrowser/$session/config → $XDG_CONFIG_HOME/qutebrowser
+# $XDG_RUNTIME_DIR/qutebrowser/$session/runtime (no symlink, regular directory)
+#
+# We then specify $XDG_RUNTIME_DIR/qutebrowser/$session as a --basedir, and the
+# files will end up in their intended locations (notice how the config directory
+# is the same for all sessions, as there is no point in keeping it separate).
+#
+# Written by ayekat in an burst of nostalgy, on a mildly cold wednesday night in
+# February 2017.
+
+#set -e
+
+# Set default values for the variables as defined in the XDG base directory spec
+# (https://specifications.freedesktop.org/basedir-spec/latest/):
+XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
+XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
+XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
+XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
+
+# Translate options: remove occurrences of -r/--restore from the list of
+# command line arguments and save the session name for later; ignore -R (TODO):
+session=default
+basedir_specified=n
+opts_read=0
+while [ $opts_read -lt $# ]; do
+ opt="$1" && shift
+ case "$opt" in
+ (--basedir) basedir_specified=y ;;
+ (-r|-[!-]*r|--restore) test $# -gt 0 && session="$1" && shift && continue ;;
+ (-R) continue ;; # TODO
+ esac
+ set -- "$@" "$opt"
+ opts_read=$((opts_read + 1))
+done
+
+# Set up session base directory, unless --basedir has been specified by the
+# user:
+if [ "$basedir_specified" != 'y' ]; then
+ basedir="$XDG_RUNTIME_DIR/qutebrowser/$session"
+ set -- --basedir "$basedir" "$@"
+ mkdir -p \
+ "$basedir" \
+ "$XDG_CONFIG_HOME/qutebrowser" \
+ "$XDG_CACHE_HOME/qutebrowser/$session" \
+ "$XDG_DATA_HOME/qutebrowser/$session" \
+ "$basedir/runtime"
+ ln -fsT "$XDG_CONFIG_HOME/qutebrowser" "$basedir/config"
+ ln -fsT "$XDG_CACHE_HOME/qutebrowser/$session" "$basedir/cache"
+ ln -fsT "$XDG_DATA_HOME/qutebrowser/$session" "$basedir/data"
+fi
+
+## Run "real" qutebrowser executable:
+#if [ "$(basename "$0")" != qutebrowser ]; then
+# exec qutebrowser "$@"
+#fi
+#spath="$(readlink -f "$0")"
+#IFS=:
+#for p in $PATH; do
+# epath="$p"/qutebrowser
+# if [ -x "$epath" ] && [ "$(readlink -f "$epath")" != "$spath" ]; then
+# exec "$epath" "$@"
+# fi
+#done
+#echo 'command not found: qutebrowser' >&2
+#exit 127