Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Created October 8, 2019 15:13
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 mgedmin/f2f881df82d25c572c583fbaed81d8f6 to your computer and use it in GitHub Desktop.
Save mgedmin/f2f881df82d25c572c583fbaed81d8f6 to your computer and use it in GitHub Desktop.
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