Last active
September 10, 2022 18:46
-
-
Save knatsakis/8cf329853330893cd2d7fa3dbd5692b0 to your computer and use it in GitHub Desktop.
qutebrowser in daemon mode + extras
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c.aliases.update({ | |
'recycle': 'quit --save _recycle', | |
'restart': 'quit --save _restart', | |
'shutdown': 'quit --save _shutdown', | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
set -o pipefail | |
DAEMON="${XDG_RUNTIME_DIR}"/qutebrowser | |
case "${1:-}" in | |
'--daemon') | |
shift | |
while true; do | |
if [ "${1:-}" == '--restore' ]; then | |
shift | |
else | |
mkdir "${DAEMON}" | |
fi | |
BASE="${DAEMON}" "${0}" --no-daemon --nowindow "${@:-}" | |
done | |
;; | |
'--no-daemon') | |
shift | |
BASE="${BASE:-$(mktemp -d -p '' qute-nodaemon-XXXXX)}" | |
SESSION="${BASE}"/data/sessions | |
while true; do | |
if ! [ -d "${BASE}"/config ]; then | |
cp -a "${HOME}/.config/qutebrowser-${USER}" "${BASE}/config" | |
fi | |
if ! [ -d "${BASE}"/data ]; then | |
cp -a "${HOME}/.local/share/qutebrowser-${USER}" "${BASE}/data" | |
fi | |
if [ "${SAVED:-}" ]; then | |
cat <&${SAVED} > "${SESSION}"/_autosave.yml | |
exec {SAVED}<&- && unset SAVED | |
fi | |
if ! python3 -m qutebrowser -B "${BASE}" "${@}"; then | |
case "${BASE}" in | |
*"${XDG_RUNTIME_DIR}"*) | |
mv "${BASE}" "$(mktemp --dry-run --tmpdir='' qute-crash-XXXXX)" | |
mkdir "${BASE}" | |
continue ;; | |
*) | |
exit 1 ;; | |
esac | |
fi | |
if [ -e "${SESSION}"/_recycle.yml ]; then | |
exec {SAVED}< "${SESSION}"/_recycle.yml | |
rm -rf "${SESSION}"/_recycle.yml | |
continue | |
fi | |
if [ -e "${SESSION}"/_restart.yml ]; then | |
exec {SAVED}< "${SESSION}"/_restart.yml | |
rm -rf "${BASE}"/* | |
continue | |
fi | |
if [ -e "${SESSION}"/_shutdown.yml ]; then | |
rm -rf "${BASE}" | |
exit 1 | |
fi | |
rm -rf "${BASE}" | |
exit 0 | |
done | |
;; | |
*) | |
until IPC=$(ls "${DAEMON}"/runtime/ipc-*); do | |
sleep 0.1 && [ -d "${DAEMON}" ] | |
done 2> /dev/null | |
ARGS=$(printf %s\\n "${@:-about:blank}") | |
jq -c . <<-EOT | socat - "${IPC}" | |
{ | |
"args": $(jq -R . <<< "${ARGS}" | jq -s .), | |
"cwd": "${PWD}", | |
"protocol_version": 1, | |
"target_arg": "window" | |
} | |
EOT | |
;; | |
esac |
Thank your for the elaboration. I tried the updates put I still get some errors.
But as I read your explanations about the script I guess I am fine running the systemd solution.
Anyway thank you very much for your Help!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One of the nice things this script does, in addition to the systemd solution you mention, is that it supports the restart/recycle/shutdown commands. See the aliases at the top.
The other is that, it always starts qutebrowser from a clean state. No cookies, web page data or caches are persisted. I have some user scripts for persisting such data on-demand, on a page by page basis (I could share them if you are interested). This way, I can keep cookies etc., only for few, select, pages where I want to stay logged in. Cookies and other data from any other page gets deleted when the last qutebrowser window closes.
All this works nicely for me, but it is something you may not want or need.