Surviving Windows as a Dev Platform
Well, I’ve tried to avoid this for years, but now I have to develop and work on Windows. I first tried WSL2, Windows Subsystem for Linux, but that has just been a mess, the main problems are:
- The file systems are completely different, you can’t for instance write a .profile to run on Windows and Linux and a Mac because the file system puts all the Windows programs in
/mnt/cand there are so many things you have to do in native Windows that this isn’t much help.
- Because it is an independent subsystem, the core user experience isn’t all that great on-base Windows. For instance, there are two command-line installers Choco and scoop that I’ve used, but to run them in WSL, you have to write them as choco.exe
- For instance, if you want the same apps in Windows that live on your Mac or Ubuntu machine, you are basically writing two different scripts.
- What I really want is to just run bash against the Windows file system
So, Vlad told me about a package called MingGW which tries to handle these problems and it is native inside Windows, so maybe I can get it to run. It has now been updated to MSYS2, so off to try it which is pretty easy, you first start the bootstrap with this, but then I discovered that installing Git For Windows actually gives you a copy of MinGW that works great
# IN powerShell make sure SSH-agent is runnning properly Get-Service ssh-agent | Set-Service -StartupType Automatic Get-Copmmand ssh | Select-Object Source ssh-agent ssh-add -l # now add your .ssh keys ssh-add .\.ssh\_your_key_.id_rsa # And let git know where it is [Environment]::SetEnvironmentVariable("GIT_SSH", "$((Get-Command ssh).Source)", [System.EnvironmentVariableTarget]::User) # install scoop scoop install git # now you are out of Powershell, and into MINGW64 shell which is bash finally! git-bash # your home directory is now /c/Users/rich which is c:\Users\rich # now you can use git to your hearts content mkdir -p ws/git cd ws/git git clone email@example.com:richtong/src --recursive # note that all Windows commands are still available so you can scoop scoop install 1passwword # or you can do an install just for mingw64 for linux tools only pacman -Sl
If you do not want to install git For Windows, then you install msys2 and you are going to have to fix all the links and make symbolics which is quite a bit harder, so I don’t recommend it:
# inside power tools assuming you have scoop or chocolatey installed scoop install msys2 msys2 # now do the package updates pacman -Syu # now you can run MSYS2 from the Windows menu pacman --sync -u # install some things first search for some packages pacman -Sl git # install the package pacman -S git # NOw relogin with MSYS2 as an Administrator, there is no sudo # Now symlink the key Windows side directories onto this side # does not work as expected, so need to set some things # and run as super user # https://stackoverflow.com/questions/61594025/symlink-in-msys2-copy-or-hard-link export MSYS=winsymlinks:nativestrict ln -s /c/Users/rich/Downloads # this will make the Downloads directly visible in Msys2 # or you can call any Windows command directly cmd //c mklink /c/User/rich/Downloads # Now you have to make the path work so edit the .bash_profieel # if you haver a git repo, now is the time to sync itm mkdir -p ws/git cd ws/git # now you have the problem that there is no SSH keychain that I can find git clone firstname.lastname@example.org:richtong/src
This way more like it, it basically symlinks all the settings and you are in
/home/rich but this is but your Windows home directory is in /c/Users/rich which is really nice. As a really nice thing, if you start the Windows Terminal in Administrator mode, you are in sudo mode in Msys2 and if you start as a user, you are in user mode.
By the way if you want to avoid all of the above, you can just turn on Developer mode in Windows 10 and then you can symlink the normal way if you then hack the registry. At least for me, that is way too complicated, so instead I’ll just runas admin when I need to
The cool thing is that you are really running Using Pacman Commands in Linux [Beginner’s Guide] (itsfoss.com), so a simple
pacman -Syu will get you the latest packages. And there is a new Windows application so a simple Windows-S for MSYS2 will boot you there directly. One nice thing about this is that if you do this, then Divvy works. With Windows Terminal, it consumes lots of the keys so you can’t use CTRL-WINDOWS-ALT for anything.
Now with all this, you can see how you can build up a nice development environment so that you can use your Bash and other Unix tools and it is in fact native on Windows. Woohoo!
And then to run real Windows commands, you can use the thingy
cmd which calls the Windows command terminal. But yo udo have
# cygpath gives the Windows path for a MSYS2 internal one # //c is the /c flag which is like bash -c cmd //c mklink "$(cygpath /c/Users/rich/Downloads)" "$(cygpath -w -a Downloads)"
My only real remaining wish is to remap the CTRL-V to ALT-V so that it works like the Mac. And also to be able to run things like scoop from within msys2 so I can script things, this doesn’t seem to work so,
cmd //c scoop search sharpkeys says that scoop is not found.
But the problem is that PowerShell is really different, so to figure out path problems, you don’t say
echo $PATH instead, you utter
$env.path because it is object oriented and immediately you can see the problem, the path in MSYS2 is completely different from the normal Windows path. Makes sense they want to isolate you from the Windows environment, but it means that most commands are not available.
Of for instance, the simple
which scoop that normally gives you the absolute path of a command looks like like
(Get-Module -ListAvailable Power*).path that it is object oriented, so commands have attributes. Pretty strange. And there is a nice decoder ring for equivalent bash commands. But in this case
which scoop for instance becomes
Get-Command scoop | Select-Object -ExpandProperty Definition which is more clear but definitely a few more characters.
Or with the older Windows cmd.exe, the you use the where command. I know right?
# to run scoop from MSYS2 which was installed by scoop itself cmd //c "$(cygpath -w -a /c/Users/rich/scoop/shims/scoop)" search sharpkeys # you can even run a Windows app from MSYS2 cmd //c "$(cygpath -w -a /c/Users/rich/scoop/shims/smartkeys.exe)"
This is long and verbose, but it is easy to script. I think it would have been better not to install MSYS2 with scoop since scoop is hiding all the paths. For some reason the Type keys doesn’t work, but you basically want to swap
Special: Left Alt(00_38) with
Special: Left Ctrl (00_1d) and then you logout out and back in!