Whilst some linux distros include a Snap install of Firefox by default; it holds up your terminal while running meaning you either need to close the browser or run multiple instances of WSL2. In my experience, it also doesn't run very well. I'd much prefer to use my every day browsers in Windows.
This project provides a simple way to open files or URLs in your favourite browsers directly from the CLI.
To install these commands, we will need to add them to our .bashrc or .zshrc files. If you're unsure which shell you're using, run:
echo $SHELL
Then, run the corresponding command:
curl -s https://raw.githubusercontent.com/reillyfeatherstone/wsl-open-win-browser/main/wsl-open-win-browser.sh >> ~/.bashrc && source ~/.bashrc
curl -s https://raw.githubusercontent.com/reillyfeatherstone/wsl-open-win-browser/main/wsl-open-win-browser.sh >> ~/.zshrc && source ~/.zshrc
The commands are super simple!
<browser> [file_path|dir_path|url]
chrome
- Opens a new chrome windowchrome <file_path>
- Opens specified file in chromechrome <dir_path>
- Opens specified directory in chromechrome <url>
- If the command can't find a corresponding file/directory at the path provided, it will presume you're requesting a URL.
firefox
- Opens a new firefox windowfirefox <file_path>
- Opens that file in firefoxfirefox <dir_path>
- Opens that directory in firefoxfirefox <url>
- If the command can't find a corresponding file/directory at the path provided, it will presume you're requesting a URL.
If you get the above error, it will probably be due to your Chrome installation being located at another path. To resolve this:
- Find the location of your chrome.exe in windows
- In WSL2, open your .bashrc / .zshrc file
- Amend the path from "/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", to the correct path.
- Reload the .bashrc / .zshrc with
source ~/.bashrc
orsource ~/.zshrc
(Note that the path must start with /mnt/ for WSL2 to find it)
If you get the above error, it will probably be due to your Firefox installation being located at another path. To resolve this:
- Find the location of your firefox.exe in windows
- In WSL2, open your .bashrc / .zshrc file
- Amend the path from "/mnt/c/Program Files/Mozilla Firefox/firefox.exe", to the correct path.
- Reload the .bashrc / .zshrc with
source ~/.bashrc
orsource ~/.zshrc
(Note that the path must start with /mnt/ for WSL2 to find it)