Ubuntu – How to change default browser AND the command line parameters used to open a link from gnome-terminal

command linedefault-browsergnomegnome-terminal

I basically have the same question that was answered over here:

How do I change the browser that gnome terminal opens links with?

Except I am running on Ubuntu 14.04 and am interested in customizing the command line arguments passed to the browser. Is there a way to do this?

Best Answer

Programs use a variety of other programs to determine the default browser - sensible-browser & xdg-open being two of them.

For xdg-open, you can use it simply by by running xdg-open http://URL, so xdg-open https://www.google.co.uk will open Google for instance.
This should be the same as running echo https://www.google.co.uk in terminal and clicking on the link should open the default browser (in my case, Firefox).
You can see what is the default browser using xdg-settings get default-web-browser:

$ xdg-settings get default-web-browser
firefox.desktop

To set values, you do xdg-settings set default-web-browser LAUNCHER-FILE.desktop:

$ xdg-settings set default-web-browser chromium-browser.desktop

So now running echo https://www.google.co.uk and clicking on the link or running xdg-open https://www.google.co.uk should open Google in the new default browser (in my case now Chromium).

Notice that it links to the program's .desktop file not it's command - this needs to be a valid file in /usr/share/applications (or ~/.local/share/applications). You can easily create your own with a custom command easily by copying a existing one and changing the 'Name' and 'Exec' lines:

$ cp /usr/share/applications/firefox.desktop ~/.local/share/applications/firefox-new-window.desktop
$ gedit ~/.local/share/applications/firefox-new-window.desktop & disown

##Then change Name and Exec lines to `Name=Firefox (New Window)` & `Exec=firefox --new-window %u` respectively
$ update-desktop-database ~/.local/share/applications/
$ xdg-settings set default-web-browser firefox-new-window.desktop

In the above I created a new launcher, edited it so it would launch a new window of Firefox, and updated the database of launcher files and set it to default. Now running xdg-open https://www.google.co.uk opens a new window of Firefox.

More info: