How to change default browser AND the command line parameters used to open a link from gnome-terminal
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:
- Desktop Entry Specifaction (how-to edit launchers)
- How to set which application is launched by xdg-open? - Ask Ubuntu
- How to properly and easy configure
xdg-open
without any enviroment? - Unix & Linux