From 97cb8e9826f8a0b856be0cf93e4a8eed732caed2 Mon Sep 17 00:00:00 2001 From: Brandon Olin Date: Thu, 8 Apr 2021 23:31:02 -0700 Subject: [PATCH] Apply icon/color for files with more than one extension --- CHANGELOG.md | 4 ++++ Terminal-Icons/Private/Resolve-Icon.ps1 | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ae0f7e..a441468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Icon and color for symlinks and junctions are now shown, along with the target path. - [**#PR23**](https://github.com/devblackops/Terminal-Icons/pull/23) Add icons/colors for common folders `.aws`, `.Azure`, `.kube`, and `.docker` (via [@cdhunt](https://github.com/cdhunt)) +### Fixed + +- Colors/icons for files with more than one extension now have the theme applied. + ## [0.2.2] 2020-01-10 ### Added diff --git a/Terminal-Icons/Private/Resolve-Icon.ps1 b/Terminal-Icons/Private/Resolve-Icon.ps1 index ee012ca..83bd868 100644 --- a/Terminal-Icons/Private/Resolve-Icon.ps1 +++ b/Terminal-Icons/Private/Resolve-Icon.ps1 @@ -43,8 +43,16 @@ function Resolve-Icon { if (-not $iconName) { if ($FileInfo.PSIsContainer) { $iconName = $icons.Types.$type[$FileInfo.Name] - } else { + } elseif ($icons.Types.$type.ContainsKey($FileInfo.Extension)) { $iconName = $icons.Types.$type[$FileInfo.Extension] + } else { + # File probably has multiple extensions + # Fallback to computing the full extension + $firstDot = $FileInfo.Name.IndexOf('.') + if ($firstDot) { + $fullExtension = $FileInfo.Name.Substring($firstDot) + $iconName = $icons.Types.$type[$fullExtension] + } } if (-not $iconName) { $iconName = $icons.Types.$type[''] @@ -54,8 +62,16 @@ function Resolve-Icon { if (-not $colorSeq) { if ($FileInfo.PSIsContainer) { $colorSeq = $colors.Types.$type[$FileInfo.Name] - } else { + } elseif ($colors.Types.$type.ContainsKey($FileInfo.Extension)) { $colorSeq = $colors.Types.$type[$FileInfo.Extension] + } else { + # File probably has multiple extensions + # Fallback to computing the full extension + $firstDot = $FileInfo.Name.IndexOf('.') + if ($firstDot) { + $fullExtension = $FileInfo.Name.Substring($firstDot) + $colorSeq = $colors.Types.$type[$fullExtension] + } } if (-not $colorSeq) { $colorSeq = $colors.Types.$type['']