From 45241fced0b41ed1cec25dd13e644b605acaf765 Mon Sep 17 00:00:00 2001 From: Joon Ro Date: Wed, 8 Jun 2022 18:34:02 +0900 Subject: [PATCH 1/3] Using a proxy function, allow params --- src/Get-ChildItemColor.psm1 | 103 ++++++++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 11 deletions(-) diff --git a/src/Get-ChildItemColor.psm1 b/src/Get-ChildItemColor.psm1 index 21b238f..e7a7a77 100644 --- a/src/Get-ChildItemColor.psm1 +++ b/src/Get-ChildItemColor.psm1 @@ -203,23 +203,104 @@ Function Out-ChildItemColor { } Function Get-ChildItemColor { - [CmdletBinding()] - Param( - [string]$Path = "" - ) +[CmdletBinding(DefaultParameterSetName='Items', HelpUri='https://go.microsoft.com/fwlink/?LinkID=2096492')] +param( + [Parameter(ParameterSetName='Items', Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='LiteralItems', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('PSPath','LP')] + [string[]] + ${LiteralPath}, + + [Parameter(Position=1)] + [string] + ${Filter}, + + [string[]] + ${Include}, + + [string[]] + ${Exclude}, + + [Alias('s')] + [switch] + ${Recurse}, + + [uint] + ${Depth}, + + [switch] + ${Force}, + + [switch] + ${Name}) + + +dynamicparam +{ + try { + $targetCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Management\Get-ChildItem', [System.Management.Automation.CommandTypes]::Cmdlet, $PSBoundParameters) + $dynamicParams = @($targetCmd.Parameters.GetEnumerator() | Microsoft.PowerShell.Core\Where-Object { $_.Value.IsDynamic }) + if ($dynamicParams.Length -gt 0) + { + $paramDictionary = [Management.Automation.RuntimeDefinedParameterDictionary]::new() + foreach ($param in $dynamicParams) + { + $param = $param.Value + + if(-not $MyInvocation.MyCommand.Parameters.ContainsKey($param.Name)) + { + $dynParam = [Management.Automation.RuntimeDefinedParameter]::new($param.Name, $param.ParameterType, $param.Attributes) + $paramDictionary.Add($param.Name, $dynParam) + } + } - Begin { - $Expression = "Get-ChildItem -Path `"$Path`" $Args" - $Items = Invoke-Expression $Expression + return $paramDictionary + } + } catch { + throw } +} + +begin +{ + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Management\Get-ChildItem', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + } catch { + throw + } +} + +process +{ + try { + $items = $scriptCmd.invoke() - Process { If ($PSCmdlet.MyInvocation.Line -Match '\|') { # pipeline is used - $Items + $items } Else { - $Items | Out-ChildItemColor + $items | Out-ChildItemColor } + } catch { + throw } } -Export-ModuleMember -Function Out-ChildItemColor, 'Get-*' +end +{ + try { + } catch { + throw + } +} +} From 771c3ab0704b5d9899e1dcf6486bb2a209a1ddf9 Mon Sep 17 00:00:00 2001 From: Joon Ro Date: Wed, 8 Jun 2022 18:34:12 +0900 Subject: [PATCH 2/3] Add a missing comma --- src/Get-ChildItemColor.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Get-ChildItemColor.psd1 b/src/Get-ChildItemColor.psd1 index a3a2a95..4a33218 100644 --- a/src/Get-ChildItemColor.psd1 +++ b/src/Get-ChildItemColor.psd1 @@ -69,7 +69,7 @@ Description = 'Get-ChildItemColor provides colored versions of Get-ChildItem Cmd # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. FunctionsToExport = @( 'Get-ChildItemColor', - 'Get-ChildItemColorFormatWide' + 'Get-ChildItemColorFormatWide', 'Out-ChildItemColor' ) From ddbb5b4c05bc285e319157858071e490801d7425 Mon Sep 17 00:00:00 2001 From: Joon Ro Date: Wed, 8 Jun 2022 18:39:22 +0900 Subject: [PATCH 3/3] Update version number --- README.org | 3 +++ src/Get-ChildItemColor.psd1 | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 7142694..bf9b811 100644 --- a/README.org +++ b/README.org @@ -111,6 +111,9 @@ $Global:GetChildItemColorVerticalSpace = 1 * Authors - [[http://github.com/joonro][Joon Ro]]. * Changelog +** v3.2.0 +- Make ~Get-ChildItemColor~ a proxy function of ~~Get-ChildItem~, so + ~Get-ChildItemColor~ supports all the parameters of the original function. ** v3.1.0 - ~Get-ChildItemColor~ only highlights names instead of highlighting the whole row. ([[https://github.com/joonro/Get-ChildItemColor/issues/30][#30]]) ** v3.0.0 diff --git a/src/Get-ChildItemColor.psd1 b/src/Get-ChildItemColor.psd1 index 4a33218..3a7e573 100644 --- a/src/Get-ChildItemColor.psd1 +++ b/src/Get-ChildItemColor.psd1 @@ -10,7 +10,7 @@ RootModule = 'Get-ChildItemColor.psm1' # Version number of this module. -ModuleVersion = '3.1.0' +ModuleVersion = '3.2.0' # Supported PSEditions # CompatiblePSEditions = @()