Skip to content

Commit

Permalink
Merge branch 'release/v.2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
joonro committed Jun 6, 2022
2 parents 12b6baf + 012b248 commit 457c272
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 57 deletions.
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ $Global:GetChildItemColorVerticalSpace = 1
* Authors
- [[http://github.com/joonro][Joon Ro]].
* Changelog
** v2.3.0
- Better handling of header printout ([[https://github.com/joonro/Get-ChildItemColor/issues/41][#41]])
** v2.2.2
- Add instructions about adding a new category.
** v2.2.1
Expand Down
13 changes: 6 additions & 7 deletions src/FileInfo.ps1
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -17,24 +16,22 @@ 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
}

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
Expand All @@ -46,6 +43,8 @@ function FileInfo {

Write-Host "Mode LastWriteTime Length Name"
Write-Host "---- ------------- ------ ----"

$Script:ShowHeader = $False
}

$Color = Get-FileColor $Item
Expand Down
2 changes: 1 addition & 1 deletion src/Get-ChildItemColor.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
RootModule = 'Get-ChildItemColor.psm1'

# Version number of this module.
ModuleVersion = '2.2.2'
ModuleVersion = '2.2.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
75 changes: 31 additions & 44 deletions src/Get-ChildItemColor.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -140,79 +136,70 @@ 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)
$scriptCmd = {& $wrappedCmd @PSBoundParameters }

$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
}
}
<#
Expand Down
8 changes: 3 additions & 5 deletions src/ProcessInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 '------- ------ ----- ----- ----- ------ -- -----------'
Expand Down

0 comments on commit 457c272

Please sign in to comment.