From c4c370208983fed8f53d82c8492fd97fba987cf6 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 20 Jan 2021 15:24:45 +0100 Subject: [PATCH] userscripts: Add QUTE_VERSION See #937 --- doc/changelog.asciidoc | 2 ++ doc/userscripts.asciidoc | 3 +++ qutebrowser/commands/userscripts.py | 2 ++ 3 files changed, 7 insertions(+) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index d6c397e85..afa431250 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -116,6 +116,8 @@ Added via a new `filesystem` entry in `completion.open_categories`. Also, a new `completion.favorite_paths` setting was added which can be used to add paths to show when `:open` is used without any input. +- New `QUTE_VERSION` variable for userscripts, which can be used to read + qutebrowser's version. - New userscripts: * `kodi` to play videos in Kodi * `qr` to generate a QR code of the current URL diff --git a/doc/userscripts.asciidoc b/doc/userscripts.asciidoc index e97a951c4..804ef5a34 100644 --- a/doc/userscripts.asciidoc +++ b/doc/userscripts.asciidoc @@ -43,6 +43,9 @@ The following environment variables will be set when a userscript is launched: qutebrowser is still in command mode. If you want to receive arguments passed to your userscript via `:spawn`, use the normal way of getting commandline arguments (e.g. `$@` in bash or `sys.argv` / `argparse` / ... in Python). +- `QUTE_VERSION`: The version of qutebrowser, as a string like "2.0.0". Note that this + was added in v2.0.0, thus older versions can only be detected by the absence of this + variable. In `command` mode: diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 6d2c2f147..5429140dd 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -26,6 +26,7 @@ from typing import cast, Any, MutableMapping, Tuple from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QSocketNotifier +import qutebrowser from qutebrowser.utils import message, log, objreg, standarddir, utils from qutebrowser.commands import runners from qutebrowser.config import websettings @@ -444,6 +445,7 @@ def run_async(tab, cmd, *args, win_id, env, verbose=False, env['QUTE_DOWNLOAD_DIR'] = downloads.download_dir() env['QUTE_COMMANDLINE_TEXT'] = objreg.get('status-command', scope='window', window=win_id).text() + env['QUTE_VERSION'] = qutebrowser.__version__ cmd_path = os.path.expanduser(cmd)