-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtabcomplete.ps1
31 lines (27 loc) · 1.47 KB
/
tabcomplete.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
if ((Test-Path Function:\TabExpansion) -and (-not (Test-Path Function:\PrevTabExpansion))) {
Rename-Item Function:\TabExpansion PrevTabExpansion
}
function AntTabExpansion ($buildFile,$lastWord) {
$buildFileDir = [regex]::Match($buildFile,'^(.+)/([^/]+)$').captures.groups[1].value
if ($buildFileDir) { $buildFileDir += "/" }
$targets = Select-Xml -Path ./$buildFile -XPath "//target[@name]" | ForEach-Object { $_.Node.Name }
$importedTargets = @()
$importedBuildFiles = Select-Xml -Path ./$buildFile -XPath "//import[@file]" | ForEach-Object { $_.Node.file }
foreach ($importedBuildFile in $importedBuildFiles) {
$isAbsolutePath = $importedBuildFile -match '/^(?:[A-Za-z]:)?\\/'
if (!$isAbsolutePath) { $importedBuildFile = $buildFileDir + $importedBuildFile }
$importedTargets += AntTabExpansion ($importedBuildFile,$lastWord)
}
return $targets + $importedTargets | Where-Object { ($_ -notlike "-*") -and ($_ -like "$lastWord*") } | Sort
}
function TabExpansion ($line,$lastWord) {
$lastBlock = [regex]::Split($line,'[|;]')[-1].TrimStart()
switch -regex ($lastBlock) {
# Execute ant tab completion for non standard ant files
"ant -f (.*\.xml) (.*)" { AntTabExpansion $matches[1] $lastWord; break }
# Execute ant tab completion for all ant targets
"ant (.*)" { AntTabExpansion "build.xml" $lastWord; break }
# Fall back on existing tab expansion
default { if (Test-Path Function:\PrevTabExpansion) { PrevTabExpansion $line $lastWord } }
}
}