From 5a62a1a49fc960852fe593f546b2982fcc3b4566 Mon Sep 17 00:00:00 2001 From: Joon Ro Date: Mon, 13 Jun 2022 19:30:05 +0900 Subject: [PATCH 1/4] Do not treat ReparsePoint as Symlink if in a OneDrive folder. --- src/Get-ChildItemColor.psm1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Get-ChildItemColor.psm1 b/src/Get-ChildItemColor.psm1 index c2a6c79..ff9b848 100644 --- a/src/Get-ChildItemColor.psm1 +++ b/src/Get-ChildItemColor.psm1 @@ -8,13 +8,17 @@ $Global:GetChildItemColorVerticalSpace = 1 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 + $inOneDrive = ($item.PSParentPath.Contains($env:OneDrive) ` + -or $item.PSParentPath.Contains($env:OneDriveConsumerOneDrive) ` + -or $item.PSParentPath.Contains($env:OneDriveCommercial)) + + if ([bool]($item.Attributes -band [IO.FileAttributes]::ReparsePoint) -and (-not $inOneDrive)) { } } From e99801d02cf601983a1c583a304903a672a3e70a Mon Sep 17 00:00:00 2001 From: Joon Ro Date: Mon, 13 Jun 2022 19:30:26 +0900 Subject: [PATCH 2/4] Capitalization --- src/Get-ChildItemColor.psm1 | 42 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Get-ChildItemColor.psm1 b/src/Get-ChildItemColor.psm1 index ff9b848..30cde14 100644 --- a/src/Get-ChildItemColor.psm1 +++ b/src/Get-ChildItemColor.psm1 @@ -5,24 +5,24 @@ $Global:GetChildItemColorVerticalSpace = 1 . "$PSScriptRoot\Get-ChildItemColorTable.ps1" -function Get-FileColor($Item) { - $Key = 'Default' - - $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' + $inOneDrive = ($item.PSParentPath.Contains($env:OneDrive) ` -or $item.PSParentPath.Contains($env:OneDriveConsumerOneDrive) ` -or $item.PSParentPath.Contains($env:OneDriveCommercial)) 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 } @@ -40,9 +40,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} @@ -51,14 +51,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 = "" @@ -93,9 +93,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 += '\' } @@ -105,7 +105,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 From b907185fc12fd35ae2384b2f1cc13e65126faac1 Mon Sep 17 00:00:00 2001 From: Joon Ro Date: Mon, 13 Jun 2022 19:37:58 +0900 Subject: [PATCH 3/4] Check if $item contains PSParentPath before the OneDrive check --- src/Get-ChildItemColor.psm1 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Get-ChildItemColor.psm1 b/src/Get-ChildItemColor.psm1 index 30cde14..4e8a8fd 100644 --- a/src/Get-ChildItemColor.psm1 +++ b/src/Get-ChildItemColor.psm1 @@ -8,9 +8,14 @@ $Global:GetChildItemColorVerticalSpace = 1 function Get-FileColor($item) { $key = 'Default' - $inOneDrive = ($item.PSParentPath.Contains($env:OneDrive) ` - -or $item.PSParentPath.Contains($env:OneDriveConsumerOneDrive) ` - -or $item.PSParentPath.Contains($env:OneDriveCommercial)) + # 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' From df5916a345db98a63fee6f15773282d7f1654237 Mon Sep 17 00:00:00 2001 From: Joon Ro Date: Mon, 13 Jun 2022 19:38:53 +0900 Subject: [PATCH 4/4] Update version --- src/Get-ChildItemColor.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Get-ChildItemColor.psd1 b/src/Get-ChildItemColor.psd1 index 8880464..a0e07f7 100644 --- a/src/Get-ChildItemColor.psd1 +++ b/src/Get-ChildItemColor.psd1 @@ -10,7 +10,7 @@ RootModule = 'Get-ChildItemColor.psm1' # Version number of this module. -ModuleVersion = '3.2.2' +ModuleVersion = '3.3.0' # Supported PSEditions # CompatiblePSEditions = @()