-
-
Save bielawb/c7d5ab02432f59d029ea9a607ab43e1a to your computer and use it in GitHub Desktop.
CommandNotFoundAction FTW!
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 = { git $alias @args }.GetNewClosure() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment