Skip to content

Commit

Permalink
Merge branch 'release/v3.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
joonro committed Jun 13, 2022
2 parents 95c2e53 + df5916a commit 1f96e3c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
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 = '3.2.2'
ModuleVersion = '3.3.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
53 changes: 31 additions & 22 deletions src/Get-ChildItemColor.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@ $Global:GetChildItemColorVerticalSpace = 1

. "$PSScriptRoot\Get-ChildItemColorTable.ps1"

function Get-FileColor($Item) {
$Key = 'Default'

if ([bool]($Item.Attributes -band [IO.FileAttributes]::ReparsePoint)) {
$Key = 'Symlink'
} elseif ($Item.GetType().Name -eq 'DirectoryInfo') {
$Key = 'Directory'
} elseif ($Item.PSobject.Properties.Name -contains "Extension") {
If ($GetChildItemColorTable.File.ContainsKey($Item.Extension)) {
$Key = $Item.Extension
function Get-FileColor($item) {
$key = 'Default'

# check if in OneDrive
if ($item.PSobject.Properties.Name -contains "PSParentPath") {
$inOneDrive = ($item.PSParentPath.Contains($env:OneDrive) `
-or $item.PSParentPath.Contains($env:OneDriveConsumerOneDrive) `
-or $item.PSParentPath.Contains($env:OneDriveCommercial))
} else {
$inOneDrive = $false
}

if ([bool]($item.Attributes -band [IO.FileAttributes]::ReparsePoint) -and (-not $inOneDrive)) {
$key = 'Symlink'
} elseif ($item.GetType().Name -eq 'DirectoryInfo') {
$key = 'Directory'
} elseif ($item.PSobject.Properties.Name -contains "Extension") {
If ($GetChildItemColorTable.File.ContainsKey($item.Extension)) {
$key = $item.Extension
}
}

$Color = $GetChildItemColorTable.File[$Key]
$Color = $GetChildItemColorTable.File[$key]
return $Color
}

Expand All @@ -36,9 +45,9 @@ function Get-ChildItemColorFormatWide {

if ($Force) {$Expression += " -Force"}

$Items = Invoke-Expression $Expression
$items = Invoke-Expression $Expression

$lnStr = $Items | Select-Object Name | Sort-Object { LengthInBufferCells("$_") } -Descending | Select-Object -First 1
$lnStr = $items | Select-Object Name | Sort-Object { LengthInBufferCells("$_") } -Descending | Select-Object -First 1
$len = LengthInBufferCells($lnStr.Name)
$width = $Host.UI.RawUI.WindowSize.Width
$cols = if ($len) {[math]::Floor(($width + 1) / ($len + 2))} else {1}
Expand All @@ -47,14 +56,14 @@ function Get-ChildItemColorFormatWide {
$i = 0
$pad = [math]::Ceiling(($width + 2) / $cols) - 3

foreach ($Item in $Items) {
if ($Item.PSobject.Properties.Name -contains "PSParentPath") {
if ($Item.PSParentPath -match "FileSystem") {
foreach ($item in $items) {
if ($item.PSobject.Properties.Name -contains "PSParentPath") {
if ($item.PSParentPath -match "FileSystem") {
$ParentType = "Directory"
$ParentName = $Item.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "")
} elseif ($Item.PSParentPath -match "Registry") {
$ParentName = $item.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "")
} elseif ($item.PSParentPath -match "Registry") {
$ParentType = "Hive"
$ParentName = $Item.PSParentPath.Replace("Microsoft.PowerShell.Core\Registry::", "")
$ParentName = $item.PSParentPath.Replace("Microsoft.PowerShell.Core\Registry::", "")
}
} else {
$ParentType = ""
Expand Down Expand Up @@ -89,9 +98,9 @@ function Get-ChildItemColorFormatWide {
$nnl = ++$i % $cols -ne 0

# truncate the item name
$toWrite = $Item.Name
$toWrite = $item.Name

if ($TrailingSlashDirectory -and $Item.GetType().Name -eq 'DirectoryInfo') {
if ($TrailingSlashDirectory -and $item.GetType().Name -eq 'DirectoryInfo') {
$toWrite += '\'
}

Expand All @@ -101,7 +110,7 @@ function Get-ChildItemColorFormatWide {
$itemLength = LengthInBufferCells($toWrite)
}

$color = Get-FileColor $Item
$color = Get-FileColor $item
$widePad = $pad - ($itemLength - $toWrite.Length)
Write-Host ("{0,-$widePad}" -f $toWrite) -Fore $color -NoNewLine:$nnl

Expand Down

0 comments on commit 1f96e3c

Please sign in to comment.