From 765a22189c3effa6482e87089739a21d438e261f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=BC=E8=80=B3?= Date: Fri, 24 Nov 2017 14:52:33 +0100 Subject: [PATCH 1/5] check if qutebrowser process is running Sometimes when qutebrowser crashes, it leaves the IPC socket file behind. In those cases this script still tried to use it, failed, and didn't open your URL at all. --- scripts/open_url_in_instance.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/open_url_in_instance.sh b/scripts/open_url_in_instance.sh index 119c3aa4f..e9c6db2a1 100755 --- a/scripts/open_url_in_instance.sh +++ b/scripts/open_url_in_instance.sh @@ -6,13 +6,14 @@ _url="$1" _qb_version='0.10.1' _proto_version=1 _ipc_socket="${XDG_RUNTIME_DIR}/qutebrowser/ipc-$(echo -n "$USER" | md5sum | cut -d' ' -f1)" +_qute_bin="/usr/bin/qutebrowser" -if [[ -e "${_ipc_socket}" ]]; then +if [[ -e "${_ipc_socket}" ]] && [[ `pgrep -f $_qute_bin` ]]; then exec printf '{"args": ["%s"], "target_arg": null, "version": "%s", "protocol_version": %d, "cwd": "%s"}\n' \ "${_url}" \ "${_qb_version}" \ "${_proto_version}" \ "${PWD}" | socat - UNIX-CONNECT:"${_ipc_socket}" else - exec /usr/bin/qutebrowser --backend webengine "$@" + exec $_qute_bin --backend webengine "$@" fi From e8db59a9efb8ea0322352579c18f76cfc773d117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=BC=E8=80=B3?= Date: Sat, 25 Nov 2017 11:09:57 +0100 Subject: [PATCH 2/5] Use socat exit status to determine if the socket is usable Instead of checking, if *any* qutebrowser process is running (which may or may not have an IPC socket where we expect it), simply launch a new instance *if socat fails*. Which it does, if: * the socket file doesn't exist (qutebrowser simply not running), or * the socket isn't connectable (qutebrowser crashed, left orphaned socket) Also put new instances into background, so the script behaves a bit more consistently. (Else it *sometimes* blocks and *sometimes doesn't*, when run.) --- scripts/open_url_in_instance.sh | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/scripts/open_url_in_instance.sh b/scripts/open_url_in_instance.sh index e9c6db2a1..85cd919d4 100755 --- a/scripts/open_url_in_instance.sh +++ b/scripts/open_url_in_instance.sh @@ -8,12 +8,8 @@ _proto_version=1 _ipc_socket="${XDG_RUNTIME_DIR}/qutebrowser/ipc-$(echo -n "$USER" | md5sum | cut -d' ' -f1)" _qute_bin="/usr/bin/qutebrowser" -if [[ -e "${_ipc_socket}" ]] && [[ `pgrep -f $_qute_bin` ]]; then - exec printf '{"args": ["%s"], "target_arg": null, "version": "%s", "protocol_version": %d, "cwd": "%s"}\n' \ - "${_url}" \ - "${_qb_version}" \ - "${_proto_version}" \ - "${PWD}" | socat - UNIX-CONNECT:"${_ipc_socket}" -else - exec $_qute_bin --backend webengine "$@" -fi +exec printf '{"args": ["%s"], "target_arg": null, "version": "%s", "protocol_version": %d, "cwd": "%s"}\n' \ + "${_url}" \ + "${_qb_version}" \ + "${_proto_version}" \ + "${PWD}" | socat - UNIX-CONNECT:"${_ipc_socket}" 2>/dev/null || $_qute_bin --backend webengine "$@" & From d4291dd4aefa1d37111832c27839e1b4e73c1e95 Mon Sep 17 00:00:00 2001 From: Rouji Date: Wed, 29 Nov 2017 08:40:40 +0100 Subject: [PATCH 3/5] don't 'exec' printf --- scripts/open_url_in_instance.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/open_url_in_instance.sh b/scripts/open_url_in_instance.sh index 85cd919d4..c4acf57a1 100755 --- a/scripts/open_url_in_instance.sh +++ b/scripts/open_url_in_instance.sh @@ -8,8 +8,8 @@ _proto_version=1 _ipc_socket="${XDG_RUNTIME_DIR}/qutebrowser/ipc-$(echo -n "$USER" | md5sum | cut -d' ' -f1)" _qute_bin="/usr/bin/qutebrowser" -exec printf '{"args": ["%s"], "target_arg": null, "version": "%s", "protocol_version": %d, "cwd": "%s"}\n' \ - "${_url}" \ - "${_qb_version}" \ - "${_proto_version}" \ - "${PWD}" | socat - UNIX-CONNECT:"${_ipc_socket}" 2>/dev/null || $_qute_bin --backend webengine "$@" & +printf '{"args": ["%s"], "target_arg": null, "version": "%s", "protocol_version": %d, "cwd": "%s"}\n' \ + "${_url}" \ + "${_qb_version}" \ + "${_proto_version}" \ + "${PWD}" | socat - UNIX-CONNECT:"${_ipc_socket}" 2>/dev/null || $_qute_bin --backend webengine "$@" & From 938198e92aea1a140523d326df2e253b50d7a3fc Mon Sep 17 00:00:00 2001 From: Rouji Date: Wed, 29 Nov 2017 08:43:02 +0100 Subject: [PATCH 4/5] quote _qute_bin (paths may contain whitespace), remove unnecessary --backend argument --- scripts/open_url_in_instance.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/open_url_in_instance.sh b/scripts/open_url_in_instance.sh index c4acf57a1..7e07c1394 100755 --- a/scripts/open_url_in_instance.sh +++ b/scripts/open_url_in_instance.sh @@ -12,4 +12,4 @@ printf '{"args": ["%s"], "target_arg": null, "version": "%s", "protocol_version" "${_url}" \ "${_qb_version}" \ "${_proto_version}" \ - "${PWD}" | socat - UNIX-CONNECT:"${_ipc_socket}" 2>/dev/null || $_qute_bin --backend webengine "$@" & + "${PWD}" | socat - UNIX-CONNECT:"${_ipc_socket}" 2>/dev/null || "$_qute_bin" "$@" & From afb4a6be51b3126563c764b8598e9d46e9b9d1bb Mon Sep 17 00:00:00 2001 From: Rouji Date: Wed, 29 Nov 2017 08:43:46 +0100 Subject: [PATCH 5/5] bump _qb_version --- scripts/open_url_in_instance.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/open_url_in_instance.sh b/scripts/open_url_in_instance.sh index 7e07c1394..6abd8b424 100755 --- a/scripts/open_url_in_instance.sh +++ b/scripts/open_url_in_instance.sh @@ -3,7 +3,7 @@ # author: Thore Bödecker (foxxx0) _url="$1" -_qb_version='0.10.1' +_qb_version='1.0.3' _proto_version=1 _ipc_socket="${XDG_RUNTIME_DIR}/qutebrowser/ipc-$(echo -n "$USER" | md5sum | cut -d' ' -f1)" _qute_bin="/usr/bin/qutebrowser"