Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bielawb
Created May 5, 2019 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bielawb/c7d5ab02432f59d029ea9a607ab43e1a to your computer and use it in GitHub Desktop.
Save bielawb/c7d5ab02432f59d029ea9a607ab43e1a to your computer and use it in GitHub Desktop.
CommandNotFoundAction FTW!
$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