config: C:\Users\USERNAME\AppData\Roaming\qutebrowser\config data: C:\Users\USERNAME\AppData\Roaming\qutebrowser\data
2021-April-1 qutebrowser v2.1.1 released. To keep up with qutebrowser releases, see github.com/qutebrowser/qutebrowser/releases, lists.schokokeks.org/pipermail/qutebrowser/, or old.reddit.com/r/qutebrowser/.
2021-March-28 Published this evolving[1] article.
If a userscript is specified with a relative path, it is relative to one of the following directories.
config\userscripts\
(works in qutebrowser v2.0.0+)
data\userscripts\
(works in all qutebrowser versions)
To find out the location of your
data
and
config
directories, run
the
:version
command from within qutebrowser.
On a default Windows
installation, this displays something like the following (with USERNAME replaced with your user name).
config: C:\Users\USERNAME\AppData\Roaming\qutebrowser\config data: C:\Users\USERNAME\AppData\Roaming\qutebrowser\data
In qutebrowser v2.0.0+,
the
default
data
and config
directories
each contain
an
empty
greasemonkey
subdirectory.
To learn about greasemonkey scripts,
which are written in JavaScript,
see
wikipedia.org/wiki/Greasemonkey.
💡 | If you don’t use these directories, it’s OK to delete them. |
When configuring qutebrowser,
I
often
do things in
my
directory.
To make it easy to get
there,
I have a shortcut to this
directory on my Windows Desktop.
Details about creating and using this shortcut
are in Infinite Ink’s
Windows Desktop Shortcuts Give me Quick Access to Everything.
Use either Windows File Explorer or the command line to
create a
userscripts
subdirectory
in either your
qutebrowser
config
or
data
directory.
💡 | If you are using qutebrowser v2.0.0+,
I recommend creating
If you are using qutebrowser v1.14.1 or earlier,
you need to
use
|
Create a plain text file
called qb-env.cmd
in the
userscripts
directory
that
you created in the previous step
that contains this:
@echo off
rem created: 2021-04-07
rem filename: qb-env.cmd
echo Hello from qb-env.cmd!
echo Working directory is...
cd
echo Code page is...
chcp
echo Environment variables that start with QUTE are...
set QUTE
echo Environment variables that start with PATH are...
set PATH
qb-env means qutebrowser environment and this batch file displays the working directory, code page, and some environment variables.
ℹ | If you are wondering why this batch file has a
.cmd
rather than
.bat
file extension, see
stackoverflow.com/questions/148968/windows-batch-files-bat-vs-cmd. |
In your
config\config.py
,
configuration file,
add this line:
config.bind(',qe', 'spawn --userscript --output "qb-env.cmd"') ^^^^^^^^ NOTE
If you do not have a
config.py
, which is qutebrowser’s configuration file, see
Infinite Ink’s
Getting Started with qutebrowser.
To tell qutebrowser about the new key binding, run the following from within qutebrowser:
:config-source
In qutebrowser, make sure you are in command mode by pressing the Esc key and then type:
,qe
This will run qb-env.cmd
and its output will be displayed
in a new qutebrowser tab
(thanks to the
argument specified in step 3 above).
On Windows, only userscripts with
.bat
,
.cmd
,
.com
,
and
.exe
extensions will be launched by qutebrowser.
This means that if you want to
run a bash or python script
from within
Windows
qutebrowser,
you need to create a
.bat
,
.cmd
,
.com
,
or
.exe
wrapper for it.
I’d rather write a bash
shell script
than a
Windows
batch file
and, thanks to
WSL (Windows’ Subsystem for Linux),[2]
most of my Windows qutebrowser scripting
is
actually
bash scripting.
In this section,
I briefly describe my
tumblelog-wrapper.cmd
Windows
userscript
and
my
tumblelog.sh
bash script
that
it calls.
I put the following line in my config.py
.
config.bind(',t', 'spawn --userscript tumblelog-wrapper.cmd')
This makes it possible to use ,t
to
launch my tumblelog-wrapper.cmd
Windows
userscript, which
adds qutebrowser’s current web page to
Infinite Ink’s
#tumblelog Portal.
💡 | When the argument to config.bind(',t', 'spawn --userscript "C:\\Users\\USERNAME\\Sync\\qb\\tumblelog-wrapper.cmd"') |
In the Windows file system, my
qutebrowser data\
directory[4]
contains
userscripts\tumblelog-wrapper.cmd
, which comprises the following
five lines.
@REM change code page so UTF-8 characters work
chcp 65001
@REM pass six QUTE_ variables to the bash script
wsl.exe /home/WSLUSERNAME/Scripts/tumblelog.sh "%QUTE_URL%" "%QUTE_TITLE%" "%QUTE_SELECTED_TEXT%" "%QUTE_COMMANDLINE_TEXT%" "%QUTE_HTML%" "%QUTE_TEXT%"
ℹ |
|
In the
WSL
file system,
my ~/Scripts/tumblelog.sh
starts out like this:
#!/bin/bash QURL=$1 QTITLE=$2 QSELECTED=$3 QCOMMANDLINE=$4 QHTMLPATH=`wslpath $5` QTEXTPATH=`wslpath $6` # below here, I use a heredoc to create a Hugo leaf bundle
I hope this is enough to get you started using a WSL bash script with qutebrowser.
I am using WSL 1 (not WSL 2).
It is likely that there is a better way to use bash scripts with qutebrowser on Windows, for example…
instead of WSL, use Git Bash, which I wrote about in Git Bash Is My Preferred Windows Shell;
or, in WSL,
use
either
the
WSLENV
environment variable
or the WSL
commands mentioned in
How can I access WIN system variables in WSL.
Instead
of calling a WSL script, you can
call a
Git Bash script by
replacing the
tumblelog-wrapper.cmd
batch file
in
the previous section
with
something like the following.
@REM The sh.exe below is part of Git For Windows "C:\Program Files\Git\bin\sh.exe" -l "C:\full\path\to\tumblelog.sh"
If both sh.exe
and tumblelog.sh
are on your path, you can use the following.
@REM IMPORTANT: Make sure the sh.exe below is not a trojan! "sh.exe" -l "tumblelog.sh"
ℹ |
|
For more about qutebrowser, see Infinite Ink’s…
data/userscripts/
. In v.2.0.0+, userscripts are in either data/userscripts/
or config/userscripts/
:version
command from within qutebrowser.