-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #887 from ctaggart/tab
adds PowerShell argument tab completion for Paket-Add
- Loading branch information
Showing
6 changed files
with
109 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
# http://stackoverflow.com/questions/30923696/add-custom-argument-completer-for-cmdlet | ||
|
||
# https://github.com/mariuszwojcik/RabbitMQTools/blob/master/TabExpansions.ps1 | ||
function createCompletionResult([string]$text, [string]$value, [string]$tooltip) { | ||
if ([string]::IsNullOrEmpty($value)) { return } | ||
if ([string]::IsNullOrEmpty($text)) { $text = $value } | ||
if ([string]::IsNullOrEmpty($tooltip)) { $tooltip = $value } | ||
$completionText = @{$true="'$value'"; $false=$value }[$value -match "\W"] | ||
$completionText = $completionText -replace '\[', '``[' -replace '\]', '``]' | ||
New-Object System.Management.Automation.CompletionResult $completionText, $text, 'ParameterValue', $tooltip | write | ||
} | ||
|
||
$findPackages = { | ||
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) | ||
Paket-FindPackages -SearchText $wordToComplete -Max 100 | % { | ||
createCompletionResult $_ $_ $_ | write | ||
} | ||
} | ||
|
||
$findPackageVersions = { | ||
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) | ||
if (-not $fakeBoundParameter.NuGet){ return } | ||
Paket-FindPackageVersions -Name $fakeBoundParameter.NuGet -Max 100 | % { | ||
createCompletionResult $_ $_ $_ | write | ||
} | ||
} | ||
|
||
# create and add $global:options to the list of completers | ||
# http://www.powertheshell.com/dynamicargumentcompletion/ | ||
if (-not $global:options) { $global:options = @{CustomArgumentCompleters = @{};NativeArgumentCompleters = @{}}} | ||
|
||
$global:options['CustomArgumentCompleters']['Paket-Add:NuGet'] = $findPackages | ||
$global:options['CustomArgumentCompleters']['Paket-Add:Version'] = $findPackageVersions | ||
|
||
$function:tabexpansion2 = $function:tabexpansion2 -replace 'End\r\n{','End { if ($null -ne $options) { $options += $global:options} else {$options = $global:options}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@{ | ||
GUID = 'e7bdf748-93e9-4e24-95a2-ace98df3d687' | ||
Author = 'Paket' | ||
Copyright = '(c) 2015 Paket. All rights reserved.' | ||
PowerShellVersion = '3.0' | ||
CLRVersion = '4.0' | ||
RootModule = 'Paket.PowerShell.dll' | ||
HelpInfoUri = 'http://fsprojects.github.io/Paket/' | ||
ScriptsToProcess = 'ArgumentTabCompletion.ps1' | ||
# the build will append these lines | ||
# ModuleVersion = '1.0.0' | ||
# } |
Oops, something went wrong.