Skip to content

Instantly share code, notes, and snippets.

Created Feb 7, 2020
What would you like to do?
Open browser based off of certain rules (like choosy for macOS)
DOMAIN=$(echo "$URL" | awk -F[/:] '{print $4}')
## Domain starts with
if [[ $DOMAIN =~ $(echo ^\($(paste -sd'|' /home/your-user/.config/url-start.txt)\)$) ]]; then
chromium-browser "$URL" & disown
elif [[ $DOMAIN =~ $(echo ^\($(paste -sd'|' /home/your-user/.config/url-is.txt)\)$) ]]; then
firefox "$URL" & disown
firefox "$URL" & disown
[Desktop Entry]
GenericName=Browser Chooser
Comment=Choose what browser to use for specific links
Exec=choosy %u
Copy link

cesarolea commented Feb 7, 2020

This is a very simple way of setting a different default browser, based off of certain rules. A poor man's version of which is one of the utilities I missed the most when switching from macOS to Linux. I use Firefox as my main browser, but like to use Chromium for certain websites that work better with Chromium. With this setup if for example I click a Gotomeeting link in an email, it will automatically open in Chromium instead of Firefox.


First, edit choosy and replace your-user with your actual username. The one included here uses Chromium as an alternate browser, but it can be anything as long as you can pass a URL as argument. Copy choosy to your path and make it executable:

cp choosy ~/bin/
chmod +x ~/bin/choosy

Copy choosy.desktop to either ~/.local/share/applications/ or /usr/share/applications/

cp choosy.desktop /usr/share/applications

Log out of your session, and log back in. Your desktop environment should offer Choosy as a default browser option. For example in Gnome it will be listed under Settings - Details - Default Applications - Web.

Finally, edit url-start.txt and url-is.txt to your liking:

  • url-start.txt contains a list of URLs that will match on the start of the URL. For example will match due to the first entry Protocol is ignored.
  • url-is.txt contains a list of URLs that will do exact matches only.

Copy both to your ~/.config folder:

cp url-* ~/.config


Simply choose a different default browser in your desktop environment and you should be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment