-
Notifications
You must be signed in to change notification settings - Fork 3
/
qutebrowser
executable file
·91 lines (84 loc) · 3.33 KB
/
qutebrowser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh -
# 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_STATE_HOME/qutebrowser/$session
# $XDG_RUNTIME_DIR/qutebrowser/$session/data/userscripts → $XDG_DATA_HOME/qutebrowser/userscripts
# $XDG_RUNTIME_DIR/qutebrowser/$session/config → $XDG_CONFIG_HOME/qutebrowser
# $XDG_RUNTIME_DIR/qutebrowser/$session/runtime (no symlink, regular directory)
#
# (note the use of the non-standard XDG_STATE_HOME)
#
# 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).
#
# DISCLAIMER: The author of this script manages all his configuration files
# manually, so this wrapper script has not been tested for the use case where
# qutebrowser itself writes to these files (and more importantly, if multiple
# such "sessions" simultaneously write to the same configuration file).
#
# YOU HAVE BEEN WARNED.
#
# Written by ayekat in an burst of nostalgy, on a mildly cold wednesday night in
# February 2017.
set -eu
# 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}"
XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.var/state}"
# 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=false
opts_read=0
while [ $opts_read -lt $# ]; do
opt="$1" && shift
case "$opt" in
(--basedir) basedir_specified=true ;;
(-r|--restore) test $# -gt 0 && session="$1" && shift && continue ;;
(-[!-]*r) test $# -gt 0 && session="$1" && shift && opt=${opt%r} ;;
(-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; then
basedir="$XDG_RUNTIME_DIR/qutebrowser/$session"
set -- --basedir "$basedir" "$@"
mkdir -p \
"$basedir" \
"$XDG_CONFIG_HOME/qutebrowser" \
"$XDG_CACHE_HOME/qutebrowser/$session" \
"$XDG_STATE_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_STATE_HOME/qutebrowser/$session" "$basedir/data"
if [ -d "$XDG_DATA_HOME/qutebrowser/userscripts" ]; then
ln -fsT "$XDG_DATA_HOME/qutebrowser/userscripts" \
"$basedir/data/userscripts"
fi
fi
# Search "real" qutebrowser executable:
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