8

I am trying to make a shortcut for Firefox from WSL2 to Windows 10 Home, but I haven't been able to do so. I am using VcXsrv, which I've set to automatically start. I can't use WSLg since I'm not on Windows 11.

Can you use apps, like Firefox, in a Windows shortcut without having to export DISPLAY manually?

NotTheDr01ds
  • 28,025

5 Answers5

12

It sounds like you:

  • Already have your DISPLAY variable set up properly and can run Firefox from the commandline in VcXsrv. That's a great start.

  • Don't yet have the DISPLAY variable exported in ~/.bashrc, since you mention having to export it manually.

If that's the case, then you'll first need to export the variable in your startup config. If you have already done this part, skip to the "Shortcut commandline" section below.

Export DISPLAY in startup

Add the following to your ~/.bashrc:

export DISPLAY="$(hostname).local:0"

That uses mDNS to pick up the proper IP address based on my answer here on the topic. If you have another DISPLAY setting that works for you, you can use it instead, but I find the hostname based approach the easiest in most cases.

Then:

source ~/.bashrc

to have it re-read the configuration. You could also restart the shell to make sure. Then make sure Firefox runs.

Shortcut commandline

The above works when you are in an interactive shell, since the rc file is sourced for interactive shells. However, when you are launching Firefox via a shortcut, you'll need to use the wsl.exe command, and by default that isn't an interactive (or login) shell.

Going from memory here, try setting your Windows shortcut to:

wsl -e bash -lic "firefox"

That will run Bash:

  • As a login shell (-l) which will source your ~/.bash_profile
  • As an interactive shell (-i) which will source your ~/.bashrc
  • And run the command (-c) firefox
NotTheDr01ds
  • 28,025
3

I recommend using the following syntax:

wsl -e bash -lic "nohup firefox &"

"&" in linux means "start in background". Without "&" we have active window with parent process (bash), with "&" but without "nohup" our process will end together with parent (bash windows).

With "nohup" and "&" all looks pretty - only Firefox process.

Ramhound
  • 44,080
1

Further to:

Windows Shortcut (Target command)

This is what works best and most reliably for me in my particular circumstances i.e. Windows 10 with WSL2 Debian.

C:\Windows\System32\wsl.exe -d Debian -- bash -lic "nohup firefox &"

Note (if migrating from GWSL)

If you used to use GWSL for launching GUI apps before upgrading to WSL2, be sure to double check through your ~/.bashrc & ~/.profile (or ~/.bash_profile) files to remove any configs that were placed there by GWSL which might inadvertently overwrite the DISPLAY environment variable to something invalid containing your nameserver IP address (from /etc/resolve.conf).

In my case the legacy GWSL configs set DISPLAY to 1.1.1.1:0.0 instead of :0 which caused things to break.

CarlJdP
  • 51
1

While trying to get a Xilinx IDE to run in WSL with the required environment and my working directory I ended up with the following:

wsl.exe -e bash -lic ". /opt/Xilinx/14.7/ISE_DS/settings64.sh && cd /mnt/c/Users/%username%/Documents/ISE_Projects && nohup ise &"

Chaining commands using && allowed me to force the desired environment and working directory before launching the program.

The %username% substitution appears to be working.

0

I wanted to set shortcuts from WSL in my windows start and taskbar, I've written a python app for that. Installation instructions are inside the github repository :)

https://github.com/cas91010491/wsl-shortcut-creator.git

Contributors are welcome :)