A bash script that allows you to choose which web browser to use when opening URLs, instead of being limited to your system's default browser.
- Interactive browser selection: Choose from all installed web browsers when opening a URL
- Automatic browser detection: Finds all browsers installed on your system that can handle HTTP/HTTPS URLs
- Multi-platform support: Detects browsers installed via:
- System packages (
/usr/share/applications) - User installations (
~/.local/share/applications) - Flatpak applications (
/var/lib/flatpak/exports/share/applications) - Local installations (
/usr/local/share/applications)
- System packages (
- Clean command extraction: Properly extracts executable commands from desktop files, including Flatpak commands
- Self-exclusion: Prevents infinite loops by excluding itself from the browser list
- Error handling: Provides clear error messages and validates user input
- Symbolic link support: Handles Flatpak symbolic links correctly
- Copy the script to your local bin directory:
cp browser-selector.sh ~/.local/bin/
chmod +x ~/.local/bin/browser-selector.sh- Copy the desktop file to your local applications directory:
cp browser-selector.desktop ~/.local/share/applications/- Update the desktop database:
update-desktop-database ~/.local/share/applications/- Set as your default browser:
xdg-settings set default-web-browser browser-selector.desktopUse the included installation script:
./install.shThis will guide you through the installation process and optionally set the browser selector as your default browser.
# Open a URL with browser selection
./browser-selector.sh "https://example.com"
# The script will show you available browsers and let you chooseOnce installed and set as your default browser, clicking any web link will:
- Show you a list of available browsers
- Let you choose which one to use
- Open the URL with your selected browser
==========================================
Browser Selector
==========================================
URL to open: https://example.com
Select a browser:
------------------------------------------
1) Brave
2) Firefox
3) Microsoft Edge
4) Ungoogled Chromium
5) Vivaldi
6) Web (Epiphany)
7) Zen Browser
------------------------------------------
Enter your choice (1-7): 3
------------------------------------------
Opening 'https://example.com' with Microsoft Edge...
Command: /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=/app/bin/edge --file-forwarding com.microsoft.Edge @@u @@
------------------------------------------
- Browser Detection: The script searches for
.desktopfiles in multiple directories that handle HTTP/HTTPS URLs - Command Extraction: It extracts the executable command from each desktop file, removing placeholder arguments like
%u - Flatpak Support: Handles Flatpak applications by following symbolic links and extracting proper Flatpak run commands
- User Selection: Presents a numbered list of browsers for user selection
- URL Opening: Launches the selected browser with the provided URL
- Firefox
- Google Chrome / Chromium
- Vivaldi
- Opera
- Epiphany (GNOME Web)
- And many others installed via system package managers
- Microsoft Edge
- Zen Browser
- Brave Browser
- Ungoogled Chromium
- Any other Flatpak browser that declares HTTP scheme handling
The script searches these directories for browser desktop files:
/usr/share/applications/- System-wide applications/usr/local/share/applications/- Local system applications~/.local/share/applications/- User applications/var/lib/flatpak/exports/share/applications/- System Flatpak applications~/.local/share/flatpak/exports/share/applications/- User Flatpak applications
- Bash 4.0 or later
- Standard Linux desktop environment with
.desktopfiles grep,find,cut,sed(standard on most Linux systems)
If your browser isn't showing up:
-
Check desktop file locations: Run
find /usr/share/applications ~/.local/share/applications /var/lib/flatpak/exports/share/applications -name "*browser_name*" 2>/dev/null -
Verify MIME type declarations: Check if the browser's
.desktopfile includesx-scheme-handler/httpin itsMimeTypefield:grep "MimeType" /path/to/browser.desktop -
Test browser detection: Use the test script to debug:
./test-func.sh
- Ensure Flatpak browsers are properly installed and have desktop files in
/var/lib/flatpak/exports/share/applications/ - Check that the symbolic links are valid and point to actual desktop files
- Verify the Flatpak browser declares HTTP scheme handling in its MIME types
- Make sure the script is executable:
chmod +x browser-selector.sh - Ensure the script path in the desktop file is correct
- Check that you have read access to all application directories
- Verify the extracted command is valid by running it manually
- For Flatpak browsers, ensure the Flatpak runtime is properly installed
- Some browsers may require additional setup or have complex launch requirements
Run the included test suite:
./test-browser-selector.shOr test browser detection specifically:
./test-func.shYou can modify browser-selector.desktop to:
- Change the name or description
- Add or remove MIME types
- Customize the icon
- Set terminal preferences
The script can be modified to:
- Change the output format
- Add browser filtering
- Implement browser preferences/favorites
- Add keyboard shortcuts for common browsers
browser-selector.sh- Main script with Flatpak supportbrowser-selector.desktop- Desktop entry fileinstall.sh- Automated installation scripttest-browser-selector.sh- Comprehensive test suitetest-func.sh- Function-specific testsREADME.md- This documentation
- Flatpak Support: Added detection for Flatpak browsers including Edge and Zen Browser
- Symbolic Link Handling: Properly handles symbolic links used by Flatpak applications
- Expanded Search Locations: Now searches 5 different application directories
- Improved Command Extraction: Better handling of complex Flatpak run commands
- Enhanced Testing: More comprehensive test suite for debugging detection issues
- Test your changes with the provided test scripts
- Ensure compatibility with both native and Flatpak browsers
- Follow bash best practices
- Update documentation as needed
This project is in the public domain. Use it however you like!
This script was created to solve the common problem where users want to choose which browser to use when clicking links, rather than being stuck with their system's default browser. It's particularly useful for:
- Web developers who need to test in multiple browsers
- Users who prefer different browsers for different tasks (e.g., Edge for work, Firefox for personal)
- Anyone who wants more control over their browsing experience
- Users with multiple browsers installed via different methods (system packages, Flatpak, etc.)
The script has evolved to support modern Linux application distribution methods like Flatpak, making it work seamlessly with browsers like Microsoft Edge and Zen Browser that are commonly distributed as Flatpak applications.