A smart browser selector for Linux that automatically opens URLs in specific browsers or profiles based on configurable regex patterns. This is useful for separating work and personal browsing contexts (e.g., opening JIRA links in a work profile and Reddit links in a personal profile).
- Pattern Matching: Route URLs to specific browsers or profiles using regex patterns.
- Default Fallback: Define a default browser for URLs that don't match any rules.
- Easy Installation: Includes an installation script to set up symlinks and desktop entry integration.
- JSON Configuration: Simple JSON file for managing rules.
- Linux (tested on Ubuntu)
- Python 3
xdg-mime(usually pre-installed on most desktop Linux distributions)
-
Clone the repository:
git clone git@github.com:ssnake/browser-selector.git cd browser-selector -
Run the installation script:
./install.sh
This will:
- Create a symlink to the script in
~/.local/bin. - Create a
.desktopfile in~/.local/share/applications. - Register
browser-selectoras the default handler forhttp,https, andtext/html.
- Create a symlink to the script in
-
Ensure
~/.local/binis in your$PATH.
The configuration file is located at ~/.config/browser-selector/config.json.
The installation script will automatically create this file from config.example.json if it doesn't exist.
{
"rules": [
{
"pattern": "https?://(.*\\.)?github\\.com/.*",
"command": "google-chrome-stable --profile-directory='Profile 1'"
},
{
"pattern": "https?://(.*\\.)?gitlab\\.com/.*",
"command": "google-chrome-stable --profile-directory='Profile 1'"
},
{
"pattern": "https?://(.*\\.)?reddit\\.com/.*",
"command": "google-chrome-stable --profile-directory='Profile 2'"
}
],
"default_browser": "firefox"
}- rules: A list of rule objects.
- pattern: A regex string to match the URL. Note that backslashes needs to be escaped in JSON (e.g.
\\.to match a literal dot). - command: The shell command to execute if the pattern matches. The URL will be appended to this command.
- pattern: A regex string to match the URL. Note that backslashes needs to be escaped in JSON (e.g.
- default_browser: The command to execute if no rules match.
To uninstall the browser selector and remove system integration:
./install.sh uninstallNote: After uninstalling, you will need to manually set your default browser again through your system settings or using update-alternatives / xdg-mime.
-
Browser not opening?
- Check if the script is executable:
chmod +x browser-selector.py - Verify your regex patterns in
config.json. - Check
~/.config/browser-selector/config.jsonfor valid JSON syntax. - Ensure the browser commands in your config are correct and exist in your
$PATH.
- Check if the script is executable:
-
Check logs: Since the script runs from the desktop environment, you might not see stdout/stderr. Try running it manually from the terminal to debug:
browser-selector https://example.com