Bash and Fish scripts to set up multiple development environments through WSL2.
The purpose is not to install the development tools/SDKs in your WSL2 distro, but to provide scripts to keep your multiple environments even/equalized. To split development environments into several WSL2 distro helps to keep each one clean and lighter.
- When you log in, the
.wsl\etc\fish\default.fish
or.wsl\etc\sh\default.sh
will execute.- This file will execute the
<distro name>.fish
or<distro>.sh
and<username>.fish
or<username>.sh
scripts. - This way you can set environment variables and execute initial scritps by distro, user or to all of them.
- This file will execute the
- It sets the DISPLAY environment variable so you can user X apps (you need a windows X server until MS release 21H2)
- It adds an entries in the windows hosts file with the pattern
<distro name>.wsl
resolving to the wsl IP. This way, you can access your distro through domain and don't have to worry if the IP changes. Example:ping ubuntu.wsl
- The configuration files are all in one place, so it's easy to find and change for all distros.
- The code explains better than me :). Look at the examples provided.
- Download de release.
- Install oh-my-fish or oh-my-bash (for fish or bash shell respectivily)
- If you are using fish and SDKMAN, install reitzig/sdkman-for-fish
- Extract the release into your choosen directory (I've choose
C:\User\<username>
) - If using fish
- remove the directories:
# rm -fr ~/.config/fish
# rm -fr ~/.config/omf
- create the symbolick links
# ln -sf ~/winhome/.wsl/etc/fish/config/fish ~/.config/fish
# ln -sf ~/winhome/.wsl/etc/fish/config/omf ~/.config/omf
# ln -sf ~/winhome/.wsl/etc/fish/default.fish ~/.config/fish/config.fish
- If using bash, edit the .bashrc file and add the follow line just before the line that loads OMB:
source $WIN_HOME/.wsl/etc/bash/default.sh
source $OSH/oh-my-bash.sh
- (warning: security issue) Change the permission to allow your user to write the file
C:\Windows\System32\drivers\etc\hosts
- Set the environment variables to point
WSL_HOME
to the folder<drive>:\<wherever you extracted>\.wsl
andWSLENV
to inform WSL which envvars it should bring from windows to the WSL distro (don't forget the/p
at end to translate the path. More, click here)
- For each WSL2 distro you have, create a sh or fish file in
.wsl\etc\<shell>
with the (lower case) distro name as the file name. Example:.wsl\etc\fish\ubuntu.fish
or.wsl\etc\sh\ubuntu.sh
- For each username you use in your WSL2 distro, create a sh or fish file in
.wsl\etc\<shell>
with the (lower case) username as the file name. Example:.wsl\etc\fish\root.fish
or.wsl\etc\sh\root.sh