Skip to content

Commit

Permalink
Merge branch 'feature/Remove-LastParentName-check' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
joonro committed Jun 6, 2022
2 parents a8bdcfc + 78ab202 commit ec30794
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 56 deletions.
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
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 ec30794

Please sign in to comment.