Set of rules to decide which browser to use to launch a url
Go to file
2022-04-05 22:04:06 -07:00
.gitignore Working Python and Go versions 2020-11-26 08:03:23 -08:00
.pre-commit-config.yaml fix pre-commit url 2022-04-05 22:04:06 -07:00
browserRuler.desktop Working Python and Go versions 2020-11-26 08:03:23 -08:00
config.go More graceful handling of bad match functions 2022-01-28 09:53:21 -08:00
go.mod Refactor to read from an hcl config file and expr rules 2022-01-28 09:46:00 -08:00
go.sum Refactor to read from an hcl config file and expr rules 2022-01-28 09:46:00 -08:00
LICENSE Update LICENSE 2021-06-21 21:38:28 -07:00
main.go Refactor to read from an hcl config file and expr rules 2022-01-28 09:46:00 -08:00
Makefile Add pre-commit hooks 2022-01-28 09:46:00 -08:00
README.md Refactor to read from an hcl config file and expr rules 2022-01-28 09:46:00 -08:00
sample-config.hcl Refactor to read from an hcl config file and expr rules 2022-01-28 09:46:00 -08:00

browser-ruler

A small program that allows writing rules to determine which browser to lauch based on the URL

Tested on an Ubuntu and Pop_OS! system but should work on anything that supports xdg

Configuration

When launched, configuration will be read first from the -config option, if provided, then from $XDG_CONFIG_HOME/browser-ruler/config.hcl, if found, and then from $HOME/.browser-ruler.hcl. If none of these are found, it will panic and ask you to provide it some configuration.

Config files are in the HCL config language with a schema defined below.

default_browser_cmd = list(string)

rule [label] {
    browser_cmd = list(string)
    match = string
}

To see some detailed samples, check out sample-config.hcl.

Writing a MatchFunc

The match expression in the config should be a MatchFunc. This can done by using any of the helper methods available:

// accepts any number of hostnames and returns a match function that matches the hostname against any of them
matchHostname(...string) MatchFunc
// accepts any number of regexps and returns a match function that matches the hostname against any of them
matchHostRegexp(...string) MatchFunc
// accepts any number of regexps and returns a match function that matches the full url string against any of them
matchRegexp(...string) MatchFunc
// accepts any number of MatchFuncs and returns a new match function that matches against any of them
matchAny(...MatchFunc) MatchFunc

If you want more flexibility, you can write your own using the expr language. Generally, this language gives you the power to write an expression that evaluates to a boolean using exposed variables. Additonally, a helper exists to convert a bool value into a MatchFunc. For example:

MatchFunc(hostname endsWith "google.com")

The following variables are avaiable for building custom match expressions.

hostname: the requested URL hostname
fullUrl: the full string of the requested URL
url: the Go url.URL struct requested URL
MatchFunc(bool) MatchFunc: constructs a match function from a bool value

Installation

make install set-default