21 lines
581 B
PowerShell
21 lines
581 B
PowerShell
if (Get-Module posh-ssh) {
|
|
return
|
|
}
|
|
|
|
$cmdNames = "ssh"
|
|
$cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name
|
|
|
|
$configFile = "$env:USERPROFILE/.ssh/config"
|
|
|
|
Register-ArgumentCompleter -CommandName $cmdNames -Native -ScriptBlock {
|
|
param($wordToComplete, $commandAst, $cursorPosition)
|
|
|
|
Get-Content $configFile | Select-String -Pattern "^Host(\s+([.A-Za-z0-9\-_]+))+\s*$" | ForEach-Object {
|
|
$_.Matches.Groups[2].Captures.Value
|
|
} | Where-Object {
|
|
$_ -like "$wordToComplete*"
|
|
} | ForEach-Object {
|
|
"$_"
|
|
}
|
|
}
|