Skip to content

Instantly share code, notes, and snippets.

@Tuxliri
Forked from cesarolea/choosy
Last active January 6, 2023 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tuxliri/6daf8a25092ed51e59d68db92813e2c8 to your computer and use it in GitHub Desktop.
Save Tuxliri/6daf8a25092ed51e59d68db92813e2c8 to your computer and use it in GitHub Desktop.
Open browser based off of certain rules (like choosy for macOS)
#!/bin/bash
URL=$1
DOMAIN=$(echo "$URL" | awk -F[/:] '{print $4}')
## Domain starts with
if [[ $DOMAIN =~ $(echo ^\($(paste -sd'|' /home/your-user/.config/url-start.txt)\)$) ]]; then
microsoft-edge "$URL" & disown
elif [[ $DOMAIN =~ $(echo ^\($(paste -sd'|' /home/your-user/.config/url-is.txt)\)$) ]]; then
microsoft-edge "$URL" & disown
else
firefox "$URL" & disown
fi
[Desktop Entry]
Name=Choosy
GenericName=Browser Chooser
Comment=Choose what browser to use for specific links
Categories=Network;
Exec=choosy %u
Type=Application
MimeType=x-scheme-handler/unknown;x-scheme-handler/about;text/html;text/xml;application/xhtml_xml;x-scheme-handler/http;x-scheme-handler/https;
@Tuxliri
Copy link
Author

Tuxliri commented Jan 6, 2023

This script allows one to set which browser handles which uri. This gist is forked from the work of @cesarolea and is here as reference for me and others. These instructions were tested on Ubuntu 22.04.
There are 2 files filtering the urls:

  • url-start.txt there are the urls which are handled if there is a partial match e.g. if here we set the uri docs.google.com, then also https://docs.google.com/user/davide/blablabla.docx will be handled by the selected browser
  • url-is.txt here the urls are matched only exactly

Installation

  1. Modify the file choosy, replacing your-user with your username
  2. Select which browser handles which case by editing the file choosy (in my example here I have microsoft edge handling the two filtered cases and firefox handling all other urls
  3. Copy choosy to your path and make it executable
cp choosy ~/bin/
chmod +x ~/bin/choosy
  1. Copy choosy.desktop to either ~/.local/share/applications/ or /usr/share/applications/:
    cp choosy.desktop ~/.local/share/applications/
  2. Execute xdg-mime default choosy.desktop x-scheme-handler/http && xdg-mime default choosy.desktop x-scheme-handler/https in the terminal to set the association.
  3. Copy both url-start.txt and url-is.txt to your ~/.config folder:
    cp url-* ~/.config

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