From 123f65cc52eea275cc2833819f5cdb43d83f2354 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 13 Jul 2016 09:02:50 -0500 Subject: [PATCH] (GH-847) Tab Completion Enhancements - Do not perform remote searches when the query starts with a local file search. - Require at least two characters before performing remote searches --- .../helpers/ChocolateyTabExpansion.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 index 5c294c7daa..0b28a349f7 100644 --- a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 +++ b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 @@ -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] } } @@ -99,17 +102,17 @@ function ChocolateyTabExpansion($lastBlock) { switch -regex ($lastBlock -replace "^$(Get-AliasPattern choco) ","") { # Handles uninstall package names - "^uninstall\s+(?[^-\s]*)$" { + "^uninstall\s+(?[^\.][^-\s]*)$" { chocoLocalPackages $matches['package'] } # Handles install package names - "^(install)\s+(?[^-\s]*)$" { + "^(install)\s+(?[^\.][^-\s]+)$" { chocoRemotePackages $matches['package'] } # Handles upgrade / uninstall package names - "^upgrade\s+(?[^-\s]*)$" { + "^upgrade\s+(?[^\.][^-\s]*)$" { chocoLocalPackagesUpgrade $matches['package'] }