शास्त्रीय आधार पर, मैं regex का इस्तेमाल किया।
उदाहरण के लिए
,
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;
}
}
}
संदर्भ http://gallery.technet.microsoft.com/scriptcenter/005d8bc7-5163-4a25-ad0d-25cffa90faf5
पॉश-Git GitTabExpansion.ps1 में TabExpansionBackup को TabExpansion नाम बदलता है।
और पॉश-गिट की पुनर्वितरित टैबएक्सपेंशन मूल टैबएक्सप्शन (टैबएक्सपेंशनबैकअप) को कॉल करता है जब पूर्णता गिट कमांड से मेल नहीं खाती है।
तो आपको केवल TabExpansionBackup को फिर से परिभाषित करना है।
(बिल्ली \ GitTabExpansion.ps1 |। -पिछले चयन 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 } }
}
}
=========== ================================================== ==================
को फिर से परिभाषित TabExpansionBackup (मूल TabExpansion)
function TabExpansionBackup {
...
### Resolve Command name & parameter name
...
### Currently target is Get-Alias & "-Name" parameter
...
}
क्या आपने यहां पढ़ा है: http://www.powertheshell.com/dynamicargumentcompletion/ –
नहीं, मुझे यह नहीं मिला था। बहुत जानकारीपूर्ण –
आप http: //powertab.codeplex पर भी एक नज़र डाल सकते हैं।कॉम/यह पावरहेल v.2 से 'गतिशील इंटेलिसेंस' है, लेकिन इसे 3.0 में भी बहुत अच्छा लगता है –