Classicamente, ho usato espressioni regolari.
per esempio,
function TabExpansion {
param($line, $lastWord)
if ($line -match '(-(\w+))\s+([^-]*$)')
{
### Resolve Command name & parameter name
$_param = $matches[2] + '*'
$_opt = $Matches[3].Split(" ,")[-1] + '*'
$_base = $Matches[3].Substring(0,$Matches[3].Length-$Matches[3].Split(" ,")[-1].length)
$_cmdlet = [regex]::Split($line, '[|;=]')[-1]
if ($_cmdlet -match '\{([^\{\}]*)$')
{
$_cmdlet = $matches[1]
}
if ($_cmdlet -match '\(([^()]*)$')
{
$_cmdlet = $matches[1]
}
$_cmdlet = $_cmdlet.Trim().Split()[0]
$_cmdlet = @(Get-Command -type 'Cmdlet,Alias,Function,Filter,ExternalScript' $_cmdlet)[0]
while ($_cmdlet.CommandType -eq 'alias')
{
$_cmdlet = @(Get-Command -type 'Cmdlet,Alias,Function,Filter,ExternalScript' $_cmdlet.Definition)[0]
}
### Currently target is Get-Alias & "-Name" parameter
if ("Get-Alias" -eq $_cmdlet.Name -and "Name" -like $_param)
{
Get-Alias -Name $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
break;
}
}
}
Riferimento http://gallery.technet.microsoft.com/scriptcenter/005d8bc7-5163-4a25-ad0d-25cffa90faf5
Posh-git rinomina TabExpansion a TabExpansionBackup in GitTabExpansion.ps1.
E TabExpansion rideterminato di posh-git chiama TabExpansion originale (TabExpansionBackup) quando i completamenti non corrispondono ai comandi git.
Quindi tutto ciò che dovete fare è ridefinire TabExpansionBackup.
(cat \ GitTabExpansion.ps1 |. Selezionare -Last 18)
============================== GitTabExpansion ps1 ==============================
if (Test-Path Function:\TabExpansion) {
Rename-Item Function:\TabExpansion TabExpansionBackup
}
function TabExpansion($line, $lastWord) {
$lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart()
switch -regex ($lastBlock) {
# Execute git tab completion for all git-related commands
"^$(Get-AliasPattern git) (.*)" { GitTabExpansion $lastBlock }
"^$(Get-AliasPattern tgit) (.*)" { GitTabExpansion $lastBlock }
# Fall back on existing tab expansion
default { if (Test-Path Function:\TabExpansionBackup) { TabExpansionBackup $line $lastWord } }
}
}
=========== ================================================== ==================
Ridefinizione TabExpansionBackup (TabExpansion originale)
function TabExpansionBackup {
...
### Resolve Command name & parameter name
...
### Currently target is Get-Alias & "-Name" parameter
...
}
Hai letto qui: http://www.powertheshell.com/dynamicargumentcompletion/ –
No, non l'avevo trovato. Molto informativo –
Puoi anche dare un'occhiata a http: //powertab.codeplex.com/è un 'intellissense dinamico' da powershell v.2 ma lo uso anche in 3.0 molto fine –