As a web developer, I usually work on a Mac at work, and on my Windows 10 PC at home.
This article descrieve how I mange to use the Windows Fork app from my WSL installation.
TL:DR
- From WSL edit your ~/.bashrc file
- Add the following alias:
alias fork='/mnt/c/Windows/System32/cmd.exe /c "%USERPROFILE%\\AppData\Local\Fork\Fork.exe "$(wslpath -w -a .)'
- Save your changes.
- Restart the terminal, so the new alias become available.
How to use
- From WSL, navigate to a project folder that use git.
- Run the alias:
fork
. - On Windows, the Fork app will open an the project git will be selected for view.
Background
I use vscode and the integrated terminal to manage my projects (for example to run Gulp.js tasks).
And as I do prefer the Linux/Mac terminal better, I configured vscode to work with the WSL bash as default.
Now, and this is important, I made symbolic link between my Window installation Work
folder at C:\Work\
and my WSL installation at /home/ubuntu/Work/
folder.
This make super easy to work with any of my project, regardless if I'm working from Windows or from WSL.
The problem with Fork and WSL
One tool I like a lot is the free git client Fork.
While I usually use git from between the vscode, or from the WSL terminal, I like Fork the best to visualize and manage my projects git branches.
Fork is available for Mac and Windows, but not for Linux. :(
And as I configured vscode to use WSL as the default bash, I was unable to launch Fork from the terminal in the current working folder, as I regulary can on Mac or Windows.
Or that is what I thought, at first. :)
"wslpath" to the rescue
wslpath is a WSL tool that converts WSL paths to Windows paths.
And since I already created a symbolic link for my Work
folder under WSL, all what was left was just to find a way to launch Fork on Windows from the WSL terminal, and to pass the current working WSL folder path converted to a Windows path.
The first part was easy enough. You can launch any Windows app fro WSL using this command: /mnt/c/Windows/System32/cmd.exe /c [PATH TO THE WINDOWS .EXE FILE]
So to launch Fork I can use this command: /mnt/c/Windows/System32/cmd.exe /c "%USERPROFILE%\AppData\Local\Fork\Fork.exe
.
The Windows variable
%USERPROFILE%
will be automatically replaced with your Windows User folder path (ex.:C:\Users\yourusername
).
You can pass a path to Fork executable file to launch the app and to automatically open the git repository on that path.
On linux, the current folder path is represented by .
. But passing this to the Fork executable on Windows means nothing. I needed a way to convert this to a full and absolute Windows path.
And that is what wslpath does!.
So the final command looks like this: /mnt/c/Windows/System32/cmd.exe /c "%USERPROFILE%\AppData\Local\Fork\Fork.exe "$(wslpath -w -a .)
I added two parameters.
The-w
parameter translate from a WSL path to a Windows path.
And the-a
parameter force result to absolute path format.
The final step is to add this working command as a fork
alias on my WSL installation, on your [WLS] user .bashrc
file.
From your WSL installation, edit the ~/.bashrc
file and add the following line: alias fork='/mnt/c/Windows/System32/cmd.exe /c "%USERPROFILE%\AppData\Local\Fork\Fork.exe "$(wslpath -w -a .)'
The result is that I can use Fork transparently from. between my WSL installation. I love it!
Happy coding!!
Top comments (1)
I get an error saying
'\wsl.localhost\Ubuntu-22.04\home\ssg\mm5-fe-customer-td'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
'Users' is not recognized as an internal or external command,