Skip to content

Instantly share code, notes, and snippets.

@bielawb
Created November 10, 2017 09:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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.
$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