diff --git a/src/FileInfo.ps1 b/src/FileInfo.ps1 index 863d40f..8eedd1c 100644 --- a/src/FileInfo.ps1 +++ b/src/FileInfo.ps1 @@ -1,6 +1,5 @@ # Helper method to write file length in a more human readable format -function Write-FileLength -{ +function Write-FileLength { Param ($Length) If ($Length -eq $null) { @@ -17,8 +16,7 @@ function Write-FileLength } # Outputs a line of a DirectoryInfo or FileInfo -function Write-Color-LS -{ +function Write-Color-LS { param ([string]$Color = "White", $Item) 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 @@ -26,15 +24,14 @@ function Write-Color-LS function FileInfo { param ( - [Parameter(Mandatory=$True,Position=1)] + [Parameter(Mandatory=$True, Position=1)] $Item ) $ParentName = $Item.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "") - If ($Script:LastParentName -ne $ParentName) { + If ($Script:LastParentName -ne $ParentName -or $Script:ShowHeader) { $Color = $GetChildItemColorTable.File['Directory'] - $ParentName = $Item.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "") Write-Host Write-Host " Directory: " -noNewLine @@ -46,6 +43,8 @@ function FileInfo { Write-Host "Mode LastWriteTime Length Name" Write-Host "---- ------------- ------ ----" + + $Script:ShowHeader = $False } $Color = Get-FileColor $Item diff --git a/src/Get-ChildItemColor.psm1 b/src/Get-ChildItemColor.psm1 index cd6d925..3139d6c 100644 --- a/src/Get-ChildItemColor.psm1 +++ b/src/Get-ChildItemColor.psm1 @@ -8,17 +8,13 @@ $Global:GetChildItemColorVerticalSpace = 1 Function Get-FileColor($Item) { $Key = 'Default' - if ([bool]($Item.Attributes -band [IO.FileAttributes]::ReparsePoint)) { + If ([bool]($Item.Attributes -band [IO.FileAttributes]::ReparsePoint)) { $Key = 'Symlink' - } Else { - If ($Item.GetType().Name -eq 'DirectoryInfo') { - $Key = 'Directory' - } Else { - If ($Item.PSobject.Properties.Name -contains "Extension") { - If ($GetChildItemColorTable.File.ContainsKey($Item.Extension)) { - $Key = $Item.Extension - } - } + } ElseIf ($Item.GetType().Name -eq 'DirectoryInfo') { + $Key = 'Directory' + } ElseIf ($Item.PSobject.Properties.Name -contains "Extension") { + If ($GetChildItemColorTable.File.ContainsKey($Item.Extension)) { + $Key = $Item.Extension } } @@ -140,28 +136,23 @@ Add-Type -assemblyname System.ServiceProcess . "$PSScriptRoot\MatchInfo.ps1" . "$PSScriptRoot\ProcessInfo.ps1" -$script:showHeader=$true +$Script:ShowHeader=$True -function Out-Default { +Function Out-Default { [CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=113362', RemotingCapability='None')] param( - [switch] - ${Transcript}, - - [Parameter(Position=0, ValueFromPipeline=$true)] - [psobject] - ${InputObject}) + [switch] ${Transcript}, + [Parameter(Position=0, ValueFromPipeline=$True)] [psobject] ${InputObject} + ) - begin - { - try { + Begin { + Try { For ($l=1; $l -lt $GetChildItemColorVerticalSpace; $l++) { Write-Host "" } $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { + If ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) { $PSBoundParameters['OutBuffer'] = 1 } $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Core\Out-Default', [System.Management.Automation.CommandTypes]::Cmdlet) @@ -169,50 +160,46 @@ function Out-Default { $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) - } catch { - throw + } Catch { + Throw } } - process - { - try { - if(($_ -is [System.IO.DirectoryInfo]) -or ($_ -is [System.IO.FileInfo])) - { + Process { + Try { + If (($_ -is [System.IO.DirectoryInfo]) -or ($_ -is [System.IO.FileInfo])) { FileInfo $_ - $_ = $null + $_ = $Null } - elseif($_ -is [System.ServiceProcess.ServiceController]) - { + ElseIf ($_ -is [System.ServiceProcess.ServiceController]) { ServiceController $_ - $_ = $null + $_ = $Null } - elseif($_ -is [Microsoft.Powershell.Commands.MatchInfo]) - { + ElseIf ($_ -is [Microsoft.Powershell.Commands.MatchInfo]) { MatchInfo $_ $_ = $null } - else { + Else { $steppablePipeline.Process($_) } - } catch { - throw + } Catch { + Throw } } - end + End { - try { + Try { For ($l=1; $l -le $GetChildItemColorVerticalSpace; $l++) { Write-Host "" } - $script:showHeader=$true + $Script:ShowHeader=$true $steppablePipeline.End() - } catch { - throw + } Catch { + Throw } } <# diff --git a/src/ProcessInfo.ps1 b/src/ProcessInfo.ps1 index 7b16aae..8e20ac1 100644 --- a/src/ProcessInfo.ps1 +++ b/src/ProcessInfo.ps1 @@ -6,13 +6,11 @@ function Write-Color-Process } function ProcessInfo { - param ( - [Parameter(Mandatory=$True,Position=1)] - $process + param ( + [Parameter(Mandatory=$True, Position=1)] $process ) - if($script:showHeader) - { + If ($script:showHeader) { Write-Host Write-Host 'Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName' Write-Host '------- ------ ----- ----- ----- ------ -- -----------'