~\ └── AppData\ └── Roaming\ └── qutebrowser\ ├── config\ │ ├── greasemonkey\ └── data\ └── greasemonkey\
Ongoing
According to
Repology,
the
newest
packaged
qutebrowser
is
.
2022-March-28
As of today, this evolving[1]
article
has been on
the web
for
This article assumes…
you know the basics about the qutebrowser web browser,
you know how to create and populate a config.py
configuration file,
and you are using qutebrowser on Windows.
A qutebrowser userscript can be run on a web page or on a fragment of a web page. To learn about userscripts, see…
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.
Examples of wrapper scripts are below.
A fresh install of qutebrowser on Windows usually creates the following directory structure.
~\ └── AppData\ └── Roaming\ └── qutebrowser\ ├── config\ │ ├── greasemonkey\ └── data\ └── greasemonkey\
Note that…
On Windows, ~
is also known as
%HOME%
and
%USERPROFILE%
.[2]
It is usually located
at
C:\Users\USERNAME
(with USERNAME
replaced with your user name).
To find out
the location of your
qutebrowser
config
and data
directories,
run
the
:version
command from within qutebrowser.
Windows default is to hide the ~\AppData\
directory.
To unhide it, click
File Explorer’s View menu
and
check
Hidden items
and/or
Greasemonkey scripts are entirely different from
qutebrowser userscripts, but I mention them here
because
a default installation of
qutebrowser
automatically creates empty greasemonkey\
directories
in
the
config
and
data
directories.
To learn about greasemonkey scripts,
which are written in
JavaScript,
see
wikipedia.org/wiki/Greasemonkey.
💡 | If you do not use these greasemonkey directories, it’s OK to delete them. |
Use either Windows File Explorer or the command line to
create a
userscripts\
directory
in either your
qutebrowser
config\
or
data\
directory.
💡 | If you are using qutebrowser v2.0.0+,
I recommend
you create
If you are using qutebrowser v1.14.1 or earlier,
you must
use
|
After the next couple steps, your directory structure will include this (assuming you are using qutebrowser v2.0.0+):
~\ └── AppData\ └── Roaming\ └── qutebrowser\ ├── config\ │ ├── greasemonkey\ │ ├── userscripts\ │ │ └── qb-env.cmd │ └── config.py └── data\ └── greasemonkey\
In the
userscripts\
directory
that
you created in the previous step,
create a plain text file
named qb-env.cmd
that contains this:
@echo off
rem created: 2022-05-06
rem filename: qb-env.cmd
rem purpose: display some parts of qutebrowser's current environment
echo Hello from qb-env.cmd!
rem next line echoes a blank line
echo(
echo Working directory is...
cd
echo(
echo Active code page is...
chcp
echo(
echo Environment variables starting with QUTE are...
set QUTE
echo(
echo Environment variables starting with PATH are...
set PATH
rem If Git Bash's sh.exe is on your path, uncomment next 7 lines
rem echo(
rem echo Git Bash: pwd
rem "sh.exe" -l -c "pwd"
rem echo(
rem echo Git Bash: printenv | grep -i qute
rem "sh.exe" -l -c "printenv | grep -i qute"
qb-env means qutebrowser environment and the above batch file displays the working directory, active 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(',qenv', 'spawn -u -o "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 this new ,qenv
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:
,qenv
This will run qb-env.cmd
and its output will be displayed
in
a new
qutebrowser
tab
(thanks to the
-o
argument
specified in
step 3
above).
💡 |
To learn about
|
The output of
this
qb-env
userscript
might be useful when you create other qutebrowser userscrpts,
for example the ones below.
I’d rather write a bash
shell script
than a
Windows
batch file
and, thanks to
WSL (Windows’ Subsystem for Linux),[3]
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 -u 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 -u "C:\\Users\\USERNAME\\Sync\\qb\\tumblelog-wrapper.cmd"') |
In the Windows file system, my
qutebrowser config\
directory[5]
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/
(or both).:version
command from within qutebrowser.Your public comment or question might immediately improve this page or help me to (eventually) improve this page.