-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Set-Env.ArgumentCompleters.ps1
45 lines (37 loc) · 1.42 KB
/
Set-Env.ArgumentCompleters.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<#
.Synopsis
Completes Set-Env.ps1 -Name, -Value .
Author: Roman Kuzmin
.Description
`Name` is completed with environment variable names.
`Value` is completed with the current location item paths.
.Link
Register-ArgumentCompleter
.Link
https://github.com/nightroman/PowerShelf
#>
Register-ArgumentCompleter -CommandName Set-Env.ps1 -ParameterName Name -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $boundParameters)
Get-Item env:\$wordToComplete* -ErrorAction 0 | .{process{
[System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'Variable', $_.Value)
}}
}
Register-ArgumentCompleter -CommandName Set-Env.ps1 -ParameterName Value -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $boundParameters)
# current folder
if (!$wordToComplete) {
$_ = @(Get-Item . -ErrorAction 0)
if ($_.Count -eq 1) {
[System.Management.Automation.CompletionResult]::new($_.FullName, '.', 'ProviderContainer', $_.FullName)
}
}
# current items
Get-Item $wordToComplete* -ErrorAction 0 | .{process{
if ($_ -is [System.IO.FileInfo]) {
[System.Management.Automation.CompletionResult]::new($_.FullName, $_.Name, 'ProviderItem', $_.FullName)
}
elseif ($_ -is [System.IO.DirectoryInfo]) {
[System.Management.Automation.CompletionResult]::new($_.FullName, $_.Name, 'ProviderContainer', $_.FullName)
}
}}
}