A handy shell function for searching wpt.fyi for tests matching a provided search term
✨ wpt-find
video demonstration (click to expand/collapse)
🛈 I sped up the search time in this screen recording for demonstration purposes. Most searches clock in at around 10-20s per search, depending on any regex complexity and if you are scraping titles from the results (multiplied by the result count).
wpt-find-demo.mp4
Table of Contents:
Add the wpt-find
source directly to your shell profile file (either .bashrc
, .bash_profile
, or .zshrc
depending on your setup). It will look something like this:
export WPT_FIND_DIRECTORY="$HOME/wpt"
source "$HOME/wpt-find/wpt-find.sh"
If you get a permission denied
error when attempting to run the file (likely on your first run), you'll need to grant execution permissions on the file in order to run it.
You can do that by running this command while in the directory that contains wpt-find.sh
:
chmod +x wpt-find.sh
This script assumes that you have a local copy of the wpt
repo, which you will need to set the related environment variable WPT_FIND_DIRECTORY
to in order for the function to properly scan the repository.
export WPT_FIND_DIRECTORY="/your/path/to/wpt"
** This script searches your local copy of the wpt
repo, so make sure to pull the latest master version on the wpt
repo before searching.
The script also provides several environment variables that you can set to customize its behavior:
WPT_FIND_MARKDOWN
: Set to1
to enable markdown output by default.WPT_FIND_LIST
: Set to1
to enable list output by default.WPT_FIND_TITLE
: Set to1
to include the title in the markdown link by default.WPT_FIND_REGEX
: Set to1
to use regex for the search by default.WPT_FIND_CLIPBOARD
: Set to1
to enable copying to the clipboard by default.
By default, all of these settings are set to 0
(disabled) and can be enabled as needed using flags (outlined below), or you can use these environment variables above to override the default behavior.
For more information on the purpose of each of these flags and how they work, check the Usage section below.
wpt-find ":dir("
# either of the below would work
wpt-find -l ":dir("
wpt-find --list ":dir("
# either of the below would work
wpt-find --markdown ":dir("
wpt-find -m ":dir("
only applies when paired with markdown -m
/--markdown
flag
# either of the below would work
wpt-find --title ":dir("
wpt-find -t ":dir("
# either of the below would work
wpt-find -r "(:is|:where)"
wpt-find --regex "(:is|:where)"
# either of the below would work
wpt-find -c ":dir("
wpt-find --copy ":dir("
# any of the below would work (flag-order-agnostic)
wpt-find --list --markdown --title --regex --copy "(:is|:where)"
wpt-find -l -m -t -r -c "(:is|:where)"
wpt-find -lmtrc "(:is|:where)"
For longer or more complex searches and larger result sets, the script may appear to pause. This is normal and is a result of processing time. The spinner indicates that wpt-find is actively working.