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 = @() diff --git a/src/Get-ChildItemColor.psm1 b/src/Get-ChildItemColor.psm1 index c2a6c79..4e8a8fd 100644 --- a/src/Get-ChildItemColor.psm1 +++ b/src/Get-ChildItemColor.psm1 @@ -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 } @@ -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} @@ -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 = "" @@ -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 += '\' } @@ -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