Use a different browser when opening a URL from the command-line

Google Chrome is my primary (i.e., default) browser to explore the internet. However, when developing websites, I prefer to debug my creations using Mozilla's Firefox Developer Edition. The local webserver is provided by DDEV and has a convenient feature; when executing ddev launch, it starts a local web server and opens the site in a browser. But the problem is that it standard uses your default browser.

Luckily, it turns out that you can easily change the default browser for your WSL 2 environment (only); you can accomplish this by setting the BROWSER environment variable. Below you can find the code snippet I've added to ~/.oh-my-zsh/custom/exports.zsh, although it should be similar for other shells/setups.

# Use Firefox Developer Edition to open URLs, for instance, when `ddev launch` is executed.
export BROWSER='eval "/mnt/c/Program Files/Firefox Developer Edition/firefox.exe"'

When invoking a command that opens a browser, like ddev launch or xdg-open https://sicse.dev, Firefox Developer Edition is used to display the web page.

For a lazy person, like me, I'm very happy :D

Category
Zsh
Oh My Zsh
Firefox Developer Edition
Windows Terminal
WSL 2
Windows
DDEV

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.