Created
July 3, 2018 21:44
-
-
Save mterrel/0effeb433213e5b014324c34d43a33bc to your computer and use it in GitHub Desktop.
Use WSL git with VS Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run WSL git from Windows, mapping some paths between unix <-> Win | |
# To use with wslgit.cmd, place them in the same directory | |
Function ToUnix { | |
# If the arg has a \, then it's probably a path. Convert it. | |
if ($args[0] -match "\\") { | |
$mapped = wsl wslpath -u `'$($args[0])`' | |
} else { | |
$mapped = $args[0] | |
} | |
# Add single quotes around each arg for bash | |
"`'$mapped`'" | |
} | |
# Convert each arg with ToUnix | |
$mappedargs = $args | % { ToUnix $_ } | |
$out = wsl git $mappedargs | |
$gitExit = $LASTEXITCODE | |
# Mapping paths in the output is extremely difficult to get right | |
# in the general case. Luckily, VS Code seems happy with most of the | |
# output paths in unix format. However, it does depend on some | |
# responses mapping to Windows paths. Transforming single-word | |
# responses that look like paths seems to be sufficient for most | |
# common VS Code operations. | |
if ($out -is [string]) { | |
$words = -split $out | |
# Only map single words that have a /, but aren't a ref (which also has slashes) | |
if (($words.Length -eq 1) -and ($words[0] -match "/") -and !($words[0] -match "^refs/")) { | |
$out = wsl wslpath -w $words[0] | |
} | |
} | |
$out | |
exit $gitExit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"git.path": "C:\\Tools\\wslgit.cmd" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Place in same directory as git.ps1 | |
SET "psgit=%~dp0git.ps1" | |
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%psgit%" %* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting the following error when vscode attempts a commit:
Any ideas? Other than that, it seems to be working.