userscripts: Add QUTE_VERSION

See #937
This commit is contained in:
Florian Bruhin 2021-01-20 15:24:45 +01:00
parent 6e03a22482
commit c4c3702089
3 changed files with 7 additions and 0 deletions

View File

@ -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

View File

@ -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:

View File

@ -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)