Skip to content

Commit b20bbdb

Browse files
Merge pull request #44 from PowershellFrameworkCollective/Development
2.0.3
2 parents b6955c0 + f566150 commit b20bbdb

File tree

7 files changed

+227
-4
lines changed

7 files changed

+227
-4
lines changed

PSUtil/PSUtil.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ModuleToProcess = 'PSUtil.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '2.0.0'
6+
ModuleVersion = '2.0.3'
77

88
# ID used to uniquely identify this module
99
GUID = '9ef51588-c40c-4064-910d-9b624b758cf6'

PSUtil/changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# Changelog 2.0.0
1+
# Changelog
2+
## Version 2.0.3 (2018-12-23)
3+
- New: Configuration setting 'PSUtil.Import.Alias.SystemOverride'. Persisting this will have PSUtil replace system default aliases.
4+
- New: Tab Expansion for PowerShellGet
5+
- New: Tab Expansion for Select-Object and Select-PSFObject
6+
7+
## Version 2.0.0 (2018-12-15)
28
- new: Command Get-PSUPathAlias lists all current path aliases
39
- new: Command Remove-PSUPathAlias removes a path alias
410
- new: Command Set-PSUPath used to implement the path alias functionality
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
11
Register-PSFTeppArgumentCompleter -Command Invoke-PSUDesktop -Parameter User -Name psutil-userprofile
22

33
Register-PSFTeppArgumentCompleter -Command Convert-PSUObject -Parameter From -Name psutil-convert-object-from
4-
Register-PSFTeppArgumentCompleter -Command Convert-PSUObject -Parameter To -Name psutil-convert-object-to
4+
Register-PSFTeppArgumentCompleter -Command Convert-PSUObject -Parameter To -Name psutil-convert-object-to
5+
6+
#region Module
7+
Register-PSFTeppArgumentCompleter -Command Update-Module -Parameter Name -Name 'PSUtil-Module-Installed'
8+
Register-PSFTeppArgumentCompleter -Command Uninstall-Module -Parameter Name -Name 'PSUtil-Module-Installed'
9+
Register-PSFTeppArgumentCompleter -Command Install-Module -Parameter Name -Name 'PSUtil-Module-Total'
10+
11+
Register-PSFTeppArgumentCompleter -Command Find-Command -Parameter Repository -Name 'PSUtil-Module-Repository'
12+
Register-PSFTeppArgumentCompleter -Command Find-DscResource -Parameter Repository -Name 'PSUtil-Module-Repository'
13+
Register-PSFTeppArgumentCompleter -Command Find-Module -Parameter Repository -Name 'PSUtil-Module-Repository'
14+
Register-PSFTeppArgumentCompleter -Command Find-RoleCapability -Parameter Repository -Name 'PSUtil-Module-Repository'
15+
Register-PSFTeppArgumentCompleter -Command Find-Script -Parameter Repository -Name 'PSUtil-Module-Repository'
16+
Register-PSFTeppArgumentCompleter -Command Install-Module -Parameter Repository -Name 'PSUtil-Module-Repository'
17+
Register-PSFTeppArgumentCompleter -Command Install-Script -Parameter Repository -Name 'PSUtil-Module-Repository'
18+
Register-PSFTeppArgumentCompleter -Command Publish-Module -Parameter Repository -Name 'PSUtil-Module-Repository'
19+
Register-PSFTeppArgumentCompleter -Command Publish-Script -Parameter Repository -Name 'PSUtil-Module-Repository'
20+
Register-PSFTeppArgumentCompleter -Command Save-Module -Parameter Repository -Name 'PSUtil-Module-Repository'
21+
Register-PSFTeppArgumentCompleter -Command Save-Script -Parameter Repository -Name 'PSUtil-Module-Repository'
22+
Register-PSFTeppArgumentCompleter -Command Get-PSRepository -Parameter Name -Name 'PSUtil-Module-Repository'
23+
Register-PSFTeppArgumentCompleter -Command Unregister-PSRepository -Parameter Name -Name 'PSUtil-Module-Repository'
24+
Register-PSFTeppArgumentCompleter -Command Register-PSRepository -Parameter PackageManagementProvider -Name 'PSUtil-Module-PackageProvider'
25+
#endregion Module
26+
27+
#region Select
28+
Register-PSFTeppArgumentCompleter -Command Select-PSFObject -Parameter Property -Name PSUtil-Input-Object
29+
Register-PSFTeppArgumentCompleter -Command Select-PSFObject -Parameter ExpandProperty -Name PSUtil-Input-Object
30+
Register-PSFTeppArgumentCompleter -Command Select-PSFObject -Parameter ExcludeProperty -Name PSUtil-Input-Object
31+
Register-PSFTeppArgumentCompleter -Command Select-PSFObject -Parameter ShowProperty -Name PSUtil-Input-Object
32+
Register-PSFTeppArgumentCompleter -Command Select-PSFObject -Parameter ShowExcludeProperty -Name PSUtil-Input-Object
33+
34+
Register-PSFTeppArgumentCompleter -Command Select-Object -Parameter Property -Name PSUtil-Input-Object
35+
Register-PSFTeppArgumentCompleter -Command Select-Object -Parameter ExpandProperty -Name PSUtil-Input-Object
36+
Register-PSFTeppArgumentCompleter -Command Select-Object -Parameter ExcludeProperty -Name PSUtil-Input-Object
37+
#endregion Select
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Register-PSFTeppScriptBlock -Name 'PSUtil-Module-Installed' -ScriptBlock {
2+
(Get-InstalledModule).Name | Select-Object -Unique
3+
}
4+
5+
Register-PSFTeppScriptBlock -Name 'PSUtil-Module-Total' -ScriptBlock {
6+
(Get-Module -ListAvailable).Name | Select-Object -Unique
7+
}
8+
9+
Register-PSFTeppScriptblock -Name 'PSUtil-Module-Repository' -ScriptBlock {
10+
(Get-PSRepository).Name
11+
}
12+
13+
Register-PSFTeppScriptblock -Name 'PSUtil-Module-PackageProvider' -ScriptBlock {
14+
(Get-PackageProvider).Name
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Set-PSFConfig -Module PSUtil -Name 'Import.Aliases.Grep' -Value $true -Initialize -Validation "bool" -Handler { } -Description "Whether the module will on import create an alias named 'grep' for Select-String"
22
Set-PSFConfig -Module PSUtil -Name 'Import.Keybindings' -Value $true -Initialize -Validation "bool" -Handler { } -Description "Whether the module will on import register keybindings in PSReadline"
3+
Set-PSFConfig -Module PSUtil -Name 'Import.Alias.SystemOverride' -Value $false -Initialize -Validation "bool" -Description "Whether the module will on import pverwrite some default aliases with custom versions. Affects 'select' and 'gm'"
34

45
Set-PSFConfig -Module 'PSUtil' -Name 'Import.DoDotSource' -Value $false -Initialize -Validation 'bool' -Description "Whether the module files should be dotsourced on import. By default, the files of this module are read as string value and invoked, which is faster but worse on debugging."
56
Set-PSFConfig -Module 'PSUtil' -Name 'Import.IndividualFiles' -Value $false -Initialize -Validation 'bool' -Description "Whether the module files should be imported individually. During the module build, all module code is compiled into few files, which are imported instead by default. Loading the compiled versions is faster, using the individual files is easier for debugging and testing out adjustments."

PSUtil/internal/scripts/aliases.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ Import-PSUAlias -Name "new" -Command "New-Object"
2121

2222
# Add alias for the better select and to avoid breaking on old command
2323
Import-PSUAlias -Name "spo" -Command "Select-PSFObject"
24-
Import-PSUAlias -Name "Select-PSUObject" -Command "Select-PSFObject"
24+
Import-PSUAlias -Name "Select-PSUObject" -Command "Select-PSFObject"
25+
26+
if (Get-PSFConfigValue -FullName 'PSUtil.Import.Alias.SystemOverride')
27+
{
28+
Remove-PSFAlias -Name select -Force
29+
Remove-PSFAlias -Name gm -Force
30+
Import-PSUAlias -Name select -Command 'Select-PSFObject'
31+
Import-PSUAlias -Name gm -Command 'Get-PSMDMember'
32+
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
Register-PSFTeppScriptblock -Name PSUtil-Input-Object -ScriptBlock {
2+
[System.Management.Automation.Language.PipelineAst]$pipelineAst = $commandAst.parent
3+
$index = $pipelineAst.PipelineElements.IndexOf($commandAst)
4+
5+
#region If it's the first command
6+
if ($index -lt 1)
7+
{
8+
return
9+
}
10+
#endregion If it's the first command
11+
12+
$properties = @()
13+
$constraintsPositive = @()
14+
15+
#region Process pre-commands
16+
$inputIndex = $index - 1
17+
:main while ($true)
18+
{
19+
if ($pipelineAst.PipelineElements[$inputIndex].CommandElements)
20+
{
21+
# Resolve command and fail if it breaks
22+
$command = Get-Command $pipelineAst.PipelineElements[$inputIndex].CommandElements[0].Value -ErrorAction Ignore
23+
if ($command -is [System.Management.Automation.AliasInfo]) { $command = $command.ResolvedCommand }
24+
if (-not $command) { break }
25+
26+
switch ($command.Name)
27+
{
28+
'Where-Object' { $inputIndex = $inputIndex - 1; continue main }
29+
'Tee-Object' { $inputIndex = $inputIndex - 1; continue main }
30+
#region Select-Object
31+
'Select-Object'
32+
{
33+
$firstAst = $pipelineAst.PipelineElements[$inputIndex].CommandElements | Where-Object { $_ -is [System.Management.Automation.Language.ArrayLiteralAst] } | Select-Object -First 1
34+
35+
foreach ($element in $firstAst.Elements)
36+
{
37+
switch ($element.GetType().FullName)
38+
{
39+
'System.Management.Automation.Language.StringConstantExpressionAst'
40+
{
41+
$constraintsPositive += $element.Value
42+
if ($element.Value -notmatch "\*") { $properties += $element.Value }
43+
}
44+
'System.Management.Automation.Language.HashtableAst'
45+
{
46+
$constraintsPositive += ($element.KeyValuePairs | Where-Object Item1 -Match '^N$|^Name$' | Select-Object -First 1).Item2.ToString().Trim('"')
47+
$properties += ($element.KeyValuePairs | Where-Object Item1 -Match '^N$|^Name$' | Select-Object -First 1).Item2.ToString().Trim('"')
48+
}
49+
}
50+
}
51+
$inputIndex = $inputIndex - 1;
52+
continue main
53+
}
54+
#endregion Select-Object
55+
#region Select-PSFObject
56+
'Select-PSFObject'
57+
{
58+
$firstAst = $pipelineAst.PipelineElements[$inputIndex].CommandElements | Where-Object { $_ -is [System.Management.Automation.Language.ArrayLiteralAst] } | Select-Object -First 1
59+
foreach ($element in $firstAst.Elements)
60+
{
61+
switch ($element.GetType().FullName)
62+
{
63+
"System.Management.Automation.Language.StringConstantExpressionAst"
64+
{
65+
$par = [PSFramework.Parameter.SelectParameter]$element.Value
66+
if ($par.Value -match "\*") { $constraintsPositive += $par.Value }
67+
else
68+
{
69+
if ($par.Value -is [System.String])
70+
{
71+
$properties += $par.Value
72+
$constraintsPositive += $par.Value
73+
}
74+
else
75+
{
76+
$properties += $par.Value["Name"]
77+
$constraintsPositive += $par.Value["Name"]
78+
}
79+
}
80+
}
81+
"System.Management.Automation.Language.HashtableAst"
82+
{
83+
$properties += ($element.KeyValuePairs | Where-Object Item1 -Match '^N$|^Name$' | Select-Object -First 1).Item2.ToString().Trim('"')
84+
$constraintsPositive += ($element.KeyValuePairs | Where-Object Item1 -Match '^N$|^Name$' | Select-Object -First 1).Item2.ToString().Trim('"')
85+
}
86+
}
87+
}
88+
$inputIndex = $inputIndex - 1;
89+
}
90+
#endregion Select-PSFObject
91+
default { break main }
92+
}
93+
}
94+
95+
else
96+
{
97+
break
98+
}
99+
}
100+
101+
# Catch moving through _all_ options in the pipeline
102+
if ($inputIndex -lt 0) { return $properties }
103+
#endregion Process pre-commands
104+
105+
106+
#region Input from command
107+
if ($pipelineAst.PipelineElements[$inputIndex].CommandElements)
108+
{
109+
if ($command = Get-Command $pipelineAst.PipelineElements[$inputIndex].CommandElements[0].Value -ErrorAction Ignore)
110+
{
111+
switch ($command.Name)
112+
{
113+
#region Default for commands
114+
default
115+
{
116+
foreach ($type in $command.OutputType.Type)
117+
{
118+
switch ($type.GetType().FullName)
119+
{
120+
'System.IO.FileInfo'
121+
{
122+
$properties += ($type.GetMembers("Instance, Public") | Where-Object MemberType -match "Field|Property").Name
123+
$properties += 'PSChildName', 'PSDrive', 'PSIsContainer', 'PSParentPath', 'PSPath', 'PSProvider', 'BaseName'
124+
break
125+
}
126+
'System.IO.DirectoryInfo'
127+
{
128+
$properties += ($type.GetMembers("Instance, Public") | Where-Object MemberType -match "Field|Property").Name
129+
$properties += 'PSChildName', 'PSDrive', 'PSIsContainer', 'PSParentPath', 'PSPath', 'PSProvider', 'BaseName', 'VersionInfo'
130+
break
131+
}
132+
default { $properties += ($type.GetMembers("Instance, Public") | Where-Object MemberType -match "Field|Property").Name }
133+
}
134+
}
135+
}
136+
#endregion Default for commands
137+
}
138+
}
139+
}
140+
#endregion Input from command
141+
142+
#region Input from Variable
143+
if ($pipelineAst.PipelineElements[$inputIndex].Expression -and $pipelineAst.PipelineElements[0].Expression[0].VariablePath)
144+
{
145+
$properties += ((Get-Variable -Name $pipelineAst.PipelineElements[0].Expression[0].VariablePath.UserPath -ValueOnly) | Select-Object -First 1 | Get-Member -MemberType Properties).Name
146+
}
147+
#endregion Input from Variable
148+
149+
$properties | Select-Object -Unique | Sort-Object | ForEach-Object {
150+
if (-not $constraintsPositive) { $_ }
151+
foreach ($constraint in $constraintsPositive)
152+
{
153+
if ($_ -like $constraint)
154+
{
155+
$_
156+
break
157+
}
158+
}
159+
}
160+
}

0 commit comments

Comments
 (0)