Created
November 10, 2017 09:45
-
-
Save bielawb/a5f1d650480bca4faed5252b7bb38cbe to your computer and use it in GitHub Desktop.
Snippet that can be added to the profile to turn git aliases into PowerShell commands. Note: this solution doesn't support parameters.
This file contains 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
$gitAliases = (git config --global -l).Where{ $_ -match '^alias\.'}.ForEach{$_ -replace '^alias\.(\w+).*', '$1'} | |
$ExecutionContext.InvokeCommand.CommandNotFoundAction = { | |
param ($name, $eventArgs) | |
if ($name -in $gitAliases) { | |
$alias = $name | |
} elseif ($aliases = $gitAliases -match [regex]::Escape($name)) { | |
$alias = $aliases | Sort-Object -Property Length | Select-Object -First 1 | |
} | |
if ($alias) { | |
$eventArgs.CommandScriptBlock = [scriptblock]::Create("git $alias") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment