Skip to content

Commit

Permalink
(GH-847) Tab Completion Enhancements
Browse files Browse the repository at this point in the history
 - Do not perform remote searches when the query starts with a local
   file search.
- Require at least two characters before performing remote searches
  • Loading branch information
ferventcoder committed Jul 13, 2016
1 parent a90c06e commit 123f65c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ function script:chocoCommands($filter) {
}

function script:chocoLocalPackages($filter) {
if ($filter -ne $null -and $filter.StartsWith(".")) { return; } #file search
@(& $script:choco list $filter -lo -r --id-starts-with) | %{ $_.Split('|')[0] }
}

function script:chocoLocalPackagesUpgrade($filter) {
if ($filter -ne $null -and $filter.StartsWith(".")) { return; } #file search
@('all|') + @(& $script:choco list $filter -lo -r --id-starts-with) | where { $_ -like "$filter*" } | %{ $_.Split('|')[0] }
}

function script:chocoRemotePackages($filter) {
if ($filter -ne $null -and $filter.StartsWith(".")) { return; } #file search
@('packages.config|') + @(& $script:choco search $filter --page=0 --page-size=30 -r --id-starts-with --order-by-popularity) | where { $_ -like "$filter*" } | %{ $_.Split('|')[0] }
}

Expand All @@ -99,17 +102,17 @@ function ChocolateyTabExpansion($lastBlock) {
switch -regex ($lastBlock -replace "^$(Get-AliasPattern choco) ","") {

# Handles uninstall package names
"^uninstall\s+(?<package>[^-\s]*)$" {
"^uninstall\s+(?<package>[^\.][^-\s]*)$" {
chocoLocalPackages $matches['package']
}

# Handles install package names
"^(install)\s+(?<package>[^-\s]*)$" {
"^(install)\s+(?<package>[^\.][^-\s]+)$" {
chocoRemotePackages $matches['package']
}

# Handles upgrade / uninstall package names
"^upgrade\s+(?<package>[^-\s]*)$" {
"^upgrade\s+(?<package>[^\.][^-\s]*)$" {
chocoLocalPackagesUpgrade $matches['package']
}

Expand Down

0 comments on commit 123f65c

Please sign in to comment.