Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to make your desktop open different URLs in different browsers, depending on the URL

How to make your desktop open different URLs in different browsers, depending on the URL

  • vim ~/bin/open-the-right-browser

    #!/bin/sh
    case "$1" in
      *git.example.com*) browser=firefox;;
      *) browser=chromium-browser;;
    esac
    exec $browser "$@"
    
  • vim ~/.local/share/applications/open-the-right-browser.desktop

    [Desktop Entry]
    Version=1.0
    Name=Web Browser
    Exec=/home/mg/bin/open-the-right-browser %U
    Terminal=false
    X-MultipleArgs=false
    Type=Application
    Icon=chromium-browser
    Categories=Network;WebBrowser;
    MimeType=text/html;text/xml;application/xhtml_xml;x-scheme-handler/http;x-scheme-handler/https;
    StartupNotify=true
    

    (repace /home/mg in the Exec= line with your actual home directory)

  • vim ~/.config/mimeapps.list

    change or add these lines:

    x-scheme-handler/http=open-the-right-browser.desktop
    x-scheme-handler/https=open-the-right-browser.desktop
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment