Commit 1b819f39 authored by Tomáš Hübelbauer's avatar Tomáš Hübelbauer

Clean up document and try last attempt with WSL

parent 538f63b7
......@@ -12,9 +12,11 @@ That's why I decided to use a pre-commit hook instead to unpack the Office file
I am on Windows and I have installed Git using the official Windows installer. This should immediately raise some eyebrows when it comes to portability. What will Git on Windows do with the hooks? Run them using Batch/PowerShell? No, Git for Windows bundles it's own Bash through MinGW. MinGW has package manager so we could potentially install the `7z` package to it and have a nice, portable script. Ordinarily you install these packages through a MinGW UI, but either I don't know shit or Git doesn't bundle this PM GUI, nor does it bundle the `mingw-get` command for installing these packages. MinGW is horrible anyway so let's figure out a different route.
Since the pre-commit hook will run as a Bash script through MinGW, but we can't manage the MinGW packages, let's settle for the host OS packages/environment. The script will run in the repository root as it's working directory. We can invoke `cmd` or `powershell` here and do the `7z` magic from there maybe? Nah, that'd bring us back to Windows only solution.
Since the pre-commit hook will run as a Bash script through MinGW, but we can't manage the MinGW packages, let's settle for the host OS packages/environment. The script will run in the repository root as it's working directory. We can invoke `cmd` or `powershell` here and do the `7z` magic from there maybe? In theory, but why not take it a step further:
How do we keep this portable without submitting to the MinGW bully? Let's utilize WSL! On Windows 10, we can invoke `bash` which will pick up the default WSL distro (learn about managing distros using `wslconfig` to see how to change the default) and we can have that execute our commands. So we can write a Unix script and use that on both Windows and Unix. I have not had success with invoking specific distros directly (using `ubuntu` in place of `bash` for example), but meh, best to stick with the default as that's likely the user preference anyway.
On Windows 10, we can invoke `bash` which will pick up the default WSL distro (learn about managing distros using [`wslconfig`](https://docs.microsoft.com/en-us/windows/wsl/wsl-config) to see how to change the default) and we can have that execute our commands. So we can write a Unix script and use that on both Windows and Unix. Problem is, `bash` in MinGW will map to MinGW Bash. `bash.exe` to MinGW Bash, too. I have not had success invoking `bash.exe` so that it actually runs WSL and not MinGW Bash. I managed to somehow not make it work even with full `bash.exe` path (trouble passing script there). One could try and invoke a specific distro directly (`ubuntu` or `opensuse-42`), but that gives a *Permission denied* error as of now because the distro paths go to system & hidden perm'd folder in Windows.
So yeah, we need to settle for PowerShell.
We're using the [bash shebang](https://stackoverflow.com/a/10383546/2715716) because we rely on `bash` anyway so `sh` won't cut it.
......
#!/usr/bin/env bash
echo "Hello from WSL?"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment