From b7cd6a484289d88c232a897552bc105a36e521e4 Mon Sep 17 00:00:00 2001 From: Michel Diemer Date: Sun, 21 Apr 2024 00:22:37 +0200 Subject: [PATCH 1/2] Added GetChildItemColorRegExTable --- src/Get-ChildItemColor.psm1 | 16 ++++++++++++++++ src/Get-ChildItemColorTable.ps1 | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/src/Get-ChildItemColor.psm1 b/src/Get-ChildItemColor.psm1 index 8c3b7b0..85d9fde 100644 --- a/src/Get-ChildItemColor.psm1 +++ b/src/Get-ChildItemColor.psm1 @@ -28,6 +28,22 @@ function Get-FileColor($item) { } $Color = $GetChildItemColorTable.File[$key] + + + $keyRegex = "" + + if ($key -ne 'Symlink') { + foreach ($regex in $GetChildItemColorRegExTable.File.Keys) { + if ($item.Name -match $regex) { + $keyRegex = $regex + } + } + } + if ($keyRegex -ne "") { + $Color = $GetChildItemColorRegExTable.File[$keyRegex] + } + + return $Color } diff --git a/src/Get-ChildItemColorTable.ps1 b/src/Get-ChildItemColorTable.ps1 index 88dd8f8..f9cbf8e 100644 --- a/src/Get-ChildItemColorTable.ps1 +++ b/src/Get-ChildItemColorTable.ps1 @@ -1,5 +1,11 @@ $global:GetChildItemColorExtensions = @{} +$global:GetChildItemColorRegExTable = @{ + File = @{ Default = $OriginalForegroundColor } +} +# starts with dot +$GetChildItemColorRegExTable.File.Add('^[.]','DarkRed') + $GetChildItemColorExtensions.Add( 'CompressedList', @( From d5f242baf02f7dd54a67db6c73574c1e99ba749c Mon Sep 17 00:00:00 2001 From: Michel Diemer Date: Sun, 21 Apr 2024 01:31:42 +0200 Subject: [PATCH 2/2] Test for hidden or system files ; added styles for those --- src/Get-ChildItemColor.psm1 | 8 ++++++-- src/Get-ChildItemColorTable.ps1 | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Get-ChildItemColor.psm1 b/src/Get-ChildItemColor.psm1 index 85d9fde..ed77fe5 100644 --- a/src/Get-ChildItemColor.psm1 +++ b/src/Get-ChildItemColor.psm1 @@ -19,8 +19,12 @@ function Get-FileColor($item) { if ([bool]($item.Attributes -band [IO.FileAttributes]::ReparsePoint) -and (-not $inOneDrive)) { $key = 'Symlink' - } elseif ($item.GetType().Name -eq 'DirectoryInfo') { - $key = 'Directory' + } elseif ($item.IsReadOnly) { + $key = 'ReadOnly' + } elseif ($item.Attributes -band [System.IO.FileAttributes]::Hidden) { + $key = 'Hidden' + } elseif ($item.Attributes -band [System.IO.FileAttributes]::System) { + $key = 'System' } elseif ($item.PSobject.Properties.Name -contains "Extension") { If ($GetChildItemColorTable.File.ContainsKey($item.Extension)) { $key = $item.Extension diff --git a/src/Get-ChildItemColorTable.ps1 b/src/Get-ChildItemColorTable.ps1 index f9cbf8e..9b53956 100644 --- a/src/Get-ChildItemColorTable.ps1 +++ b/src/Get-ChildItemColorTable.ps1 @@ -1,8 +1,10 @@ $global:GetChildItemColorExtensions = @{} +$global:GetChildItemColorProps = @{} $global:GetChildItemColorRegExTable = @{ File = @{ Default = $OriginalForegroundColor } } + # starts with dot $GetChildItemColorRegExTable.File.Add('^[.]','DarkRed') @@ -174,6 +176,10 @@ $global:GetChildItemColorTable = @{ Match = @{ Default = $OriginalForegroundColor } } +#$GetChildItemColorTable.File.Add('Archive',"DarkRed") +$GetChildItemColorTable.File.Add('Hidden',"DarkRed") +$GetChildItemColorTable.File.Add('System',"DarkRed") +$GetChildItemColorTable.File.Add('ReadOnly',"DarkRed") $GetChildItemColorTable.File.Add('Directory', "Blue") $GetChildItemColorTable.File.Add('Symlink', "Cyan")