Skip to content

Commit 1985be7

Browse files
committed
Add ability to disable displaying icon or color themes
1 parent d9b1bc4 commit 1985be7

7 files changed

Lines changed: 149 additions & 62 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Added
1111

1212
- [**#44**](https://github.com/devblackops/Terminal-Icons/pull/44) Added icons for .msi, .msix, .msixbundle, .appx, .appxbundle, .deb, .rpm, .jar, .srt, .lrc, .ass, .wav, .acc, .opus, .vmdk, .vhdx, .iso. (via [@KaranKad](https://github.com/KaranKad))
13+
- Added option to turn off displaying custom icons or colors with `-DisableIconTheme` and `-DisableColorTheme` switches on the `Set-TerminalIconsTheme` command.
1314

1415
### Changed
1516

Terminal-Icons/Private/Resolve-Icon.ps1

Lines changed: 76 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -31,73 +31,101 @@ function Resolve-Icon {
3131
switch ($FileInfo.LinkType) {
3232
# Determine symlink or junction icon and color
3333
'Junction' {
34-
$iconName = $icons.Types.($type)['junction']
35-
$colorSeq = $colors.Types.($type)['junction']
34+
if ($icons) {
35+
$iconName = $icons.Types.($type)['junction']
36+
} else {
37+
$iconName = $null
38+
}
39+
if ($colors) {
40+
$colorSeq = $colors.Types.($type)['junction']
41+
} else {
42+
$colorSet = $script:colorReset
43+
}
3644
$displayInfo['Target'] = '' + $FileInfo.Target
3745
break
3846
}
3947
'SymbolicLink' {
40-
$iconName = $icons.Types.($type)['symlink']
41-
$colorSeq = $colors.Types.($type)['symlink']
48+
if ($icons) {
49+
$iconName = $icons.Types.($type)['symlink']
50+
} else {
51+
$iconName = $null
52+
}
53+
if ($colors) {
54+
$colorSeq = $colors.Types.($type)['symlink']
55+
} else {
56+
$colorSet = $script:colorReset
57+
}
4258
$displayInfo['Target'] = '' + $FileInfo.Target
4359
break
4460
} default {
45-
# Determine normal directory icon and color
46-
$iconName = $icons.Types.$type.WellKnown[$FileInfo.Name]
47-
if (-not $iconName) {
48-
if ($FileInfo.PSIsContainer) {
49-
$iconName = $icons.Types.$type[$FileInfo.Name]
50-
} elseif ($icons.Types.$type.ContainsKey($FileInfo.Extension)) {
51-
$iconName = $icons.Types.$type[$FileInfo.Extension]
52-
} else {
53-
# File probably has multiple extensions
54-
# Fallback to computing the full extension
55-
$firstDot = $FileInfo.Name.IndexOf('.')
56-
if ($firstDot -ne -1) {
57-
$fullExtension = $FileInfo.Name.Substring($firstDot)
58-
$iconName = $icons.Types.$type[$fullExtension]
59-
}
60-
}
61-
if (-not $iconName) {
62-
$iconName = $icons.Types.$type['']
63-
}
64-
65-
# Fallback if everything has gone horribly wrong
61+
if ($icons) {
62+
# Determine normal directory icon and color
63+
$iconName = $icons.Types.$type.WellKnown[$FileInfo.Name]
6664
if (-not $iconName) {
6765
if ($FileInfo.PSIsContainer) {
68-
$iconName = 'nf-oct-file_directory'
66+
$iconName = $icons.Types.$type[$FileInfo.Name]
67+
} elseif ($icons.Types.$type.ContainsKey($FileInfo.Extension)) {
68+
$iconName = $icons.Types.$type[$FileInfo.Extension]
6969
} else {
70-
$iconName = 'nf-fa-file'
70+
# File probably has multiple extensions
71+
# Fallback to computing the full extension
72+
$firstDot = $FileInfo.Name.IndexOf('.')
73+
if ($firstDot -ne -1) {
74+
$fullExtension = $FileInfo.Name.Substring($firstDot)
75+
$iconName = $icons.Types.$type[$fullExtension]
76+
}
7177
}
72-
}
73-
}
74-
$colorSeq = $colors.Types.$type.WellKnown[$FileInfo.Name]
75-
if (-not $colorSeq) {
76-
if ($FileInfo.PSIsContainer) {
77-
$colorSeq = $colors.Types.$type[$FileInfo.Name]
78-
} elseif ($colors.Types.$type.ContainsKey($FileInfo.Extension)) {
79-
$colorSeq = $colors.Types.$type[$FileInfo.Extension]
80-
} else {
81-
# File probably has multiple extensions
82-
# Fallback to computing the full extension
83-
$firstDot = $FileInfo.Name.IndexOf('.')
84-
if ($firstDot -ne -1) {
85-
$fullExtension = $FileInfo.Name.Substring($firstDot)
86-
$colorSeq = $colors.Types.$type[$fullExtension]
78+
if (-not $iconName) {
79+
$iconName = $icons.Types.$type['']
80+
}
81+
82+
# Fallback if everything has gone horribly wrong
83+
if (-not $iconName) {
84+
if ($FileInfo.PSIsContainer) {
85+
$iconName = 'nf-oct-file_directory'
86+
} else {
87+
$iconName = 'nf-fa-file'
88+
}
8789
}
8890
}
91+
} else {
92+
$iconName = $null
93+
}
94+
if ($colors) {
95+
$colorSeq = $colors.Types.$type.WellKnown[$FileInfo.Name]
8996
if (-not $colorSeq) {
90-
$colorSeq = $colors.Types.$type['']
91-
}
97+
if ($FileInfo.PSIsContainer) {
98+
$colorSeq = $colors.Types.$type[$FileInfo.Name]
99+
} elseif ($colors.Types.$type.ContainsKey($FileInfo.Extension)) {
100+
$colorSeq = $colors.Types.$type[$FileInfo.Extension]
101+
} else {
102+
# File probably has multiple extensions
103+
# Fallback to computing the full extension
104+
$firstDot = $FileInfo.Name.IndexOf('.')
105+
if ($firstDot -ne -1) {
106+
$fullExtension = $FileInfo.Name.Substring($firstDot)
107+
$colorSeq = $colors.Types.$type[$fullExtension]
108+
}
109+
}
110+
if (-not $colorSeq) {
111+
$colorSeq = $colors.Types.$type['']
112+
}
92113

93-
# Fallback if everything has gone horribly wrong
94-
if (-not $colorSeq) {
95-
$colorSeq = $script:colorReset
114+
# Fallback if everything has gone horribly wrong
115+
if (-not $colorSeq) {
116+
$colorSeq = $script:colorReset
117+
}
96118
}
119+
} else {
120+
$colorSeq = $script:colorReset
97121
}
98122
}
99123
}
100-
$displayInfo['Icon'] = $glyphs[$iconName]
124+
if ($iconName) {
125+
$displayInfo['Icon'] = $glyphs[$iconName]
126+
} else {
127+
$displayInfo['Icon'] = $null
128+
}
101129
$displayInfo['Color'] = $colorSeq
102130
$displayInfo
103131
}

Terminal-Icons/Private/Set-Theme.ps1

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@ function Set-Theme {
33
[CmdletBinding()]
44
param(
55
[Parameter(Mandatory)]
6+
[AllowNull()]
7+
[AllowEmptyString()]
68
[string]$Name,
79

810
[ValidateSet('Color', 'Icon')]
911
[Parameter(Mandatory)]
1012
[string]$Type
1113
)
1214

13-
if (-not $script:userThemeData.Themes.$Type.ContainsKey($Name)) {
14-
Write-Error "$Type theme [$Name] not found."
15-
} else {
16-
$script:userThemeData."Current$($Type)Theme" = $Name
17-
$script:prefs."Current$($Type)Theme" = $Name
18-
Save-Theme -Theme $userThemeData.Themes.$Type[$Name] -Type $type
15+
if ([string]::IsNullOrEmpty($Name)) {
16+
$script:userThemeData."Current$($Type)Theme" = $null
17+
$script:prefs."Current$($Type)Theme" = ''
1918
Save-Preferences $script:prefs
19+
} else {
20+
if (-not $script:userThemeData.Themes.$Type.ContainsKey($Name)) {
21+
Write-Error "$Type theme [$Name] not found."
22+
} else {
23+
$script:userThemeData."Current$($Type)Theme" = $Name
24+
$script:prefs."Current$($Type)Theme" = $Name
25+
Save-Theme -Theme $userThemeData.Themes.$Type[$Name] -Type $type
26+
Save-Preferences $script:prefs
27+
}
2028
}
2129
}

Terminal-Icons/Public/Format-TerminalIcons.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
function Format-TerminalIcons {
32
<#
43
.SYNOPSIS
@@ -34,6 +33,10 @@ function Format-TerminalIcons {
3433

3534
process {
3635
$displayInfo = Resolve-Icon $FileInfo
37-
"$($displayInfo.Color)$($displayInfo.Icon) $($FileInfo.Name)$($displayInfo.Target)$($script:colorReset)"
36+
if ($displayInfo.Icon) {
37+
"$($displayInfo.Color)$($displayInfo.Icon) $($FileInfo.Name)$($displayInfo.Target)$($script:colorReset)"
38+
} else {
39+
"$($displayInfo.Color)$($FileInfo.Name)$($displayInfo.Target)$($script:colorReset)"
40+
}
3841
}
3942
}

Terminal-Icons/Public/Get-TerminalIconsTheme.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,21 @@ function Get-TerminalIconsTheme {
2222
[CmdletBinding()]
2323
param()
2424

25+
$iconTheme = if ($script:userThemeData.CurrentIconTheme) {
26+
[pscustomobject]$script:userThemeData.Themes.Icon[$script:userThemeData.CurrentIconTheme]
27+
} else {
28+
$null
29+
}
30+
31+
$colorTheme = if ($script:userThemeData.CurrentColorTheme) {
32+
[pscustomobject]$script:userThemeData.Themes.Color[$script:userThemeData.CurrentColorTheme]
33+
} else {
34+
$null
35+
}
36+
2537
[pscustomobject]@{
2638
PSTypeName = 'TerminalIconsTheme'
27-
Color = [pscustomobject]$script:userThemeData.Themes.Color[$script:userThemeData.CurrentColorTheme]
28-
Icon = [pscustomobject]$script:userThemeData.Themes.Icon[$script:userThemeData.CurrentIconTheme]
39+
Color = $colorTheme
40+
Icon = $iconTheme
2941
}
3042
}

Terminal-Icons/Public/Set-TerminalIconsTheme.ps1

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ function Set-TerminalIconsTheme {
88
The name of a registered color theme to use.
99
.PARAMETER IconTheme
1010
The name of a registered icon theme to use.
11+
.PARAMETER DisableColorTheme
12+
Disables custom colors and uses default terminal color.
13+
.PARAMETER DisableIconTheme
14+
Disables custom icons and shows only shows the directory or file name.
1115
.PARAMETER Force
1216
Bypass confirmation messages.
1317
.EXAMPLE
@@ -18,6 +22,14 @@ function Set-TerminalIconsTheme {
1822
PS> Set-TerminalIconsTheme -IconTheme devblackops
1923
2024
Set the icon theme to 'devblackops'.
25+
.EXAMPLE
26+
PS> Set-TerminalIconsTheme -DisableIconTheme
27+
28+
Disable Terminal-Icons custom icons and only show custom colors.
29+
.EXAMPLE
30+
PS> Set-TerminalIconsTheme -DisableColorTheme
31+
32+
Disable Terminal-Icons custom colors and only show custom icons.
2133
.INPUTS
2234
System.String
2335
@@ -33,21 +45,37 @@ function Set-TerminalIconsTheme {
3345
.NOTES
3446
This function supercedes Set-TerminalIconsColorTheme and Set-TerminalIconsIconTheme. They have been deprecated.
3547
#>
36-
[cmdletbinding(SupportsShouldProcess)]
48+
[cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = 'theme')]
3749
param(
50+
[Parameter(ParameterSetName = 'theme')]
3851
[ArgumentCompleter({
3952
(Get-TerminalIconsIconTheme).Keys | Sort-Object
4053
})]
4154
[string]$IconTheme,
4255

56+
[Parameter(ParameterSetName = 'theme')]
4357
[ArgumentCompleter({
4458
(Get-TerminalIconsColorTheme).Keys | Sort-Object
4559
})]
4660
[string]$ColorTheme,
4761

62+
[Parameter(ParameterSetName = 'notheme')]
63+
[switch]$DisableColorTheme,
64+
65+
[Parameter(ParameterSetName = 'notheme')]
66+
[switch]$DisableIconTheme,
67+
4868
[switch]$Force
4969
)
5070

71+
if ($DisableIconTheme.IsPresent) {
72+
Set-Theme -Name $null -Type Icon
73+
}
74+
75+
if ($DisableColorTheme.IsPresent) {
76+
Set-Theme -Name $null -Type Color
77+
}
78+
5179
if ($ColorTheme) {
5280
if ($Force -or $PSCmdlet.ShouldProcess($ColorTheme, 'Set color theme')) {
5381
Set-Theme -Name $ColorTheme -Type Color

Terminal-Icons/Public/Show-TerminalIconsTheme.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,27 @@ function Show-TerminalIconsTheme {
3333

3434
$theme = Get-TerminalIconsTheme
3535

36+
# Use the default theme if the icon theme has been disabled
37+
if ($theme.Icon) {
38+
$themeName = $theme.Icon.Name
39+
} else {
40+
$themeName = $script:defaultTheme
41+
}
42+
3643
$directories = @(
3744
[IO.DirectoryInfo]::new('ExampleFolder')
38-
$script:userThemeData.Themes.Icon[$theme.Icon.Name].Types.Directories.WellKnown.Keys.ForEach({
45+
$script:userThemeData.Themes.Icon[$themeName].Types.Directories.WellKnown.Keys.ForEach({
3946
[IO.DirectoryInfo]::new($_)
4047
})
4148
)
4249
$wellKnownFiles = @(
4350
[IO.FileInfo]::new('ExampleFile')
44-
$script:userThemeData.Themes.Icon[$theme.Icon.Name].Types.Files.WellKnown.Keys.ForEach({
51+
$script:userThemeData.Themes.Icon[$themeName].Types.Files.WellKnown.Keys.ForEach({
4552
[IO.FileInfo]::new($_)
4653
})
4754
)
4855

49-
$extensions = $script:userThemeData.Themes.Icon[$theme.Icon.Name].Types.Files.Keys.Where({$_ -ne 'WellKnown'}).ForEach({
56+
$extensions = $script:userThemeData.Themes.Icon[$themeName].Types.Files.Keys.Where({$_ -ne 'WellKnown'}).ForEach({
5057
[IO.FileInfo]::new("example$_")
5158
})
5259

0 commit comments

Comments
 (0)