pwsh-conf/Modules/posh-ssh/posh-ssh.psm1

21 lines
581 B
PowerShell
Raw Normal View History

2022-08-16 06:43:25 +00:00
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 {
"$_"
}
}