Skip to content

Commit 457c272

Browse files
committed
Merge branch 'release/v.2.3.0'
2 parents 12b6baf + 012b248 commit 457c272

File tree

5 files changed

+43
-57
lines changed

5 files changed

+43
-57
lines changed

README.org

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ $Global:GetChildItemColorVerticalSpace = 1
116116
* Authors
117117
- [[http://github.com/joonro][Joon Ro]].
118118
* Changelog
119+
** v2.3.0
120+
- Better handling of header printout ([[https://github.com/joonro/Get-ChildItemColor/issues/41][#41]])
119121
** v2.2.2
120122
- Add instructions about adding a new category.
121123
** v2.2.1

src/FileInfo.ps1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Helper method to write file length in a more human readable format
2-
function Write-FileLength
3-
{
2+
function Write-FileLength {
43
Param ($Length)
54

65
If ($Length -eq $null) {
@@ -17,24 +16,22 @@ function Write-FileLength
1716
}
1817

1918
# Outputs a line of a DirectoryInfo or FileInfo
20-
function Write-Color-LS
21-
{
19+
function Write-Color-LS {
2220
param ([string]$Color = "White", $Item)
2321

2422
Write-host ("{0,-7} {1,25} {2,10} {3}" -f $Item.mode, ([String]::Format("{0,10} {1,8}", $Item.LastWriteTime.ToString("d"), $Item.LastWriteTime.ToString("t"))), (Write-FileLength $Item.length), $Item.name) -ForegroundColor $Color
2523
}
2624

2725
function FileInfo {
2826
param (
29-
[Parameter(Mandatory=$True,Position=1)]
27+
[Parameter(Mandatory=$True, Position=1)]
3028
$Item
3129
)
3230

3331
$ParentName = $Item.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "")
3432

35-
If ($Script:LastParentName -ne $ParentName) {
33+
If ($Script:LastParentName -ne $ParentName -or $Script:ShowHeader) {
3634
$Color = $GetChildItemColorTable.File['Directory']
37-
$ParentName = $Item.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "")
3835

3936
Write-Host
4037
Write-Host " Directory: " -noNewLine
@@ -46,6 +43,8 @@ function FileInfo {
4643

4744
Write-Host "Mode LastWriteTime Length Name"
4845
Write-Host "---- ------------- ------ ----"
46+
47+
$Script:ShowHeader = $False
4948
}
5049

5150
$Color = Get-FileColor $Item

src/Get-ChildItemColor.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
RootModule = 'Get-ChildItemColor.psm1'
1111

1212
# Version number of this module.
13-
ModuleVersion = '2.2.2'
13+
ModuleVersion = '2.2.3'
1414

1515
# Supported PSEditions
1616
# CompatiblePSEditions = @()

src/Get-ChildItemColor.psm1

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@ $Global:GetChildItemColorVerticalSpace = 1
88
Function Get-FileColor($Item) {
99
$Key = 'Default'
1010

11-
if ([bool]($Item.Attributes -band [IO.FileAttributes]::ReparsePoint)) {
11+
If ([bool]($Item.Attributes -band [IO.FileAttributes]::ReparsePoint)) {
1212
$Key = 'Symlink'
13-
} Else {
14-
If ($Item.GetType().Name -eq 'DirectoryInfo') {
15-
$Key = 'Directory'
16-
} Else {
17-
If ($Item.PSobject.Properties.Name -contains "Extension") {
18-
If ($GetChildItemColorTable.File.ContainsKey($Item.Extension)) {
19-
$Key = $Item.Extension
20-
}
21-
}
13+
} ElseIf ($Item.GetType().Name -eq 'DirectoryInfo') {
14+
$Key = 'Directory'
15+
} ElseIf ($Item.PSobject.Properties.Name -contains "Extension") {
16+
If ($GetChildItemColorTable.File.ContainsKey($Item.Extension)) {
17+
$Key = $Item.Extension
2218
}
2319
}
2420

@@ -140,79 +136,70 @@ Add-Type -assemblyname System.ServiceProcess
140136
. "$PSScriptRoot\MatchInfo.ps1"
141137
. "$PSScriptRoot\ProcessInfo.ps1"
142138

143-
$script:showHeader=$true
139+
$Script:ShowHeader=$True
144140

145-
function Out-Default {
141+
Function Out-Default {
146142
[CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=113362', RemotingCapability='None')]
147143
param(
148-
[switch]
149-
${Transcript},
150-
151-
[Parameter(Position=0, ValueFromPipeline=$true)]
152-
[psobject]
153-
${InputObject})
144+
[switch] ${Transcript},
145+
[Parameter(Position=0, ValueFromPipeline=$True)] [psobject] ${InputObject}
146+
)
154147

155-
begin
156-
{
157-
try {
148+
Begin {
149+
Try {
158150
For ($l=1; $l -lt $GetChildItemColorVerticalSpace; $l++) {
159151
Write-Host ""
160152
}
161153

162154
$outBuffer = $null
163-
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
164-
{
155+
If ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) {
165156
$PSBoundParameters['OutBuffer'] = 1
166157
}
167158
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Core\Out-Default', [System.Management.Automation.CommandTypes]::Cmdlet)
168159
$scriptCmd = {& $wrappedCmd @PSBoundParameters }
169160

170161
$steppablePipeline = $scriptCmd.GetSteppablePipeline()
171162
$steppablePipeline.Begin($PSCmdlet)
172-
} catch {
173-
throw
163+
} Catch {
164+
Throw
174165
}
175166
}
176167

177-
process
178-
{
179-
try {
180-
if(($_ -is [System.IO.DirectoryInfo]) -or ($_ -is [System.IO.FileInfo]))
181-
{
168+
Process {
169+
Try {
170+
If (($_ -is [System.IO.DirectoryInfo]) -or ($_ -is [System.IO.FileInfo])) {
182171
FileInfo $_
183-
$_ = $null
172+
$_ = $Null
184173
}
185174

186-
elseif($_ -is [System.ServiceProcess.ServiceController])
187-
{
175+
ElseIf ($_ -is [System.ServiceProcess.ServiceController]) {
188176
ServiceController $_
189-
$_ = $null
177+
$_ = $Null
190178
}
191179

192-
elseif($_ -is [Microsoft.Powershell.Commands.MatchInfo])
193-
{
180+
ElseIf ($_ -is [Microsoft.Powershell.Commands.MatchInfo]) {
194181
MatchInfo $_
195182
$_ = $null
196183
}
197-
else {
184+
Else {
198185
$steppablePipeline.Process($_)
199186
}
200-
} catch {
201-
throw
187+
} Catch {
188+
Throw
202189
}
203190
}
204191

205-
end
192+
End
206193
{
207-
try {
194+
Try {
208195
For ($l=1; $l -le $GetChildItemColorVerticalSpace; $l++) {
209196
Write-Host ""
210197
}
211198

212-
$script:showHeader=$true
199+
$Script:ShowHeader=$true
213200
$steppablePipeline.End()
214-
} catch {
215-
throw
201+
} Catch {
202+
Throw
216203
}
217204
}
218205
<#

src/ProcessInfo.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ function Write-Color-Process
66
}
77

88
function ProcessInfo {
9-
param (
10-
[Parameter(Mandatory=$True,Position=1)]
11-
$process
9+
param (
10+
[Parameter(Mandatory=$True, Position=1)] $process
1211
)
1312

14-
if($script:showHeader)
15-
{
13+
If ($script:showHeader) {
1614
Write-Host
1715
Write-Host 'Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName'
1816
Write-Host '------- ------ ----- ----- ----- ------ -- -----------'

0 commit comments

Comments
 (0)