Skip to content

Commit ed386c6

Browse files
committed
Add cmd to remove icon or color theme
1 parent 181fd5f commit ed386c6

2 files changed

Lines changed: 184 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
function Remove-TerminalIconsTheme {
2+
<#
3+
.SYNOPSIS
4+
Removes a color or icon theme
5+
.DESCRIPTION
6+
Removes a given icon or color theme. In order to be removed, a theme must not be active.
7+
.PARAMETER IconTheme
8+
The icon theme to remove.
9+
.PARAMETER ColorTheme
10+
The color theme to remove.
11+
.EXAMPLE
12+
PS> Remove-TerminalIconsTheme -IconTheme MyAwesomeTheme
13+
14+
Removes the icon theme 'MyAwesomeTheme'
15+
.EXAMPLE
16+
PS> Remove-TerminalIconsTheme -ColorTheme MyAwesomeTheme
17+
18+
Removes the color theme 'MyAwesomeTheme'
19+
.INPUTS
20+
System.String
21+
22+
The name of the color or icon theme to remove.
23+
.OUTPUTS
24+
None.
25+
.LINK
26+
Set-TerminalIconsTheme
27+
.LINK
28+
Add-TerminalIconsColorTheme
29+
.LINK
30+
Add-TerminalIconsIconTheme
31+
.LINK
32+
Get-TerminalIconsTheme
33+
.NOTES
34+
A theme must not be active in order to be removed.
35+
#>
36+
[cmdletbinding()]
37+
param(
38+
[ArgumentCompleter({
39+
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
40+
(Get-TerminalIconsIconTheme).Keys | Sort-Object
41+
})]
42+
[string]$IconTheme,
43+
44+
[ArgumentCompleter({
45+
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
46+
(Get-TerminalIconsColorTheme).Keys | Sort-Object
47+
})]
48+
[string]$ColorTheme
49+
)
50+
51+
$currentTheme = Get-TerminalIconsTheme
52+
$themeStoragePath = Get-ThemeStoragePath
53+
54+
if ($ColorTheme) {
55+
if ($currentTheme.Color.Name -ne $ColorTheme) {
56+
$themePath = Join-Path $themeStoragePath "$($ColorTheme)_color.xml"
57+
if (-not (Test-Path $themePath)) {
58+
Write-Error "Could not find theme file [$themePath]"
59+
} else {
60+
if ($userThemeData.Themes.Color.ContainsKey($ColorTheme)) {
61+
$userThemeData.Themes.Color.Remove($ColorTheme)
62+
} else {
63+
# We shouldn't be here
64+
Write-Error "Color theme [$ColorTheme] is not registered."
65+
}
66+
Remove-Item $themePath -Force
67+
}
68+
} else {
69+
Write-Error ("Color theme [{0}] is active. Please select another theme before removing this it." -f $ColorTheme)
70+
}
71+
}
72+
73+
if ($IconTheme) {
74+
if ($currentTheme.Icon.Name -ne $IconTheme) {
75+
$themePath = Join-Path $themeStoragePath "$($IconTheme)_icon.xml"
76+
if (-not (Test-Path $themePath)) {
77+
Write-Error "Could not find theme file [$themePath]"
78+
} else {
79+
if ($userThemeData.Themes.Icon.ContainsKey($IconTheme)) {
80+
$userThemeData.Themes.Icon.Remove($IconTheme)
81+
} else {
82+
# We shouldn't be here
83+
Write-Error "Icon theme [$IconTheme] is not registered."
84+
}
85+
Remove-Item $themePath -Force
86+
}
87+
} else {
88+
Write-Error ("Icon theme [{0}] is active. Please select another theme before removing this it." -f $IconTheme)
89+
}
90+
}
91+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
external help file: Terminal-Icons-help.xml
3+
Module Name: Terminal-Icons
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Remove-TerminalIconsTheme
9+
10+
## SYNOPSIS
11+
Removes a color or icon theme
12+
13+
## SYNTAX
14+
15+
```
16+
Remove-TerminalIconsTheme [[-IconTheme] <String>] [[-ColorTheme] <String>] [<CommonParameters>]
17+
```
18+
19+
## DESCRIPTION
20+
Removes a given icon or color theme.
21+
In order to be removed, a theme must not be active.
22+
23+
## EXAMPLES
24+
25+
### EXAMPLE 1
26+
```
27+
Remove-TerminalIconsTheme -IconTheme MyAwesomeTheme
28+
```
29+
30+
Removes the icon theme 'MyAwesomeTheme'
31+
32+
### EXAMPLE 2
33+
```
34+
Remove-TerminalIconsTheme -ColorTheme MyAwesomeTheme
35+
```
36+
37+
Removes the color theme 'MyAwesomeTheme'
38+
39+
## PARAMETERS
40+
41+
### -IconTheme
42+
The icon theme to remove.
43+
44+
```yaml
45+
Type: String
46+
Parameter Sets: (All)
47+
Aliases:
48+
49+
Required: False
50+
Position: 1
51+
Default value: None
52+
Accept pipeline input: False
53+
Accept wildcard characters: False
54+
```
55+
56+
### -ColorTheme
57+
The color theme to remove.
58+
59+
```yaml
60+
Type: String
61+
Parameter Sets: (All)
62+
Aliases:
63+
64+
Required: False
65+
Position: 2
66+
Default value: None
67+
Accept pipeline input: False
68+
Accept wildcard characters: False
69+
```
70+
71+
### CommonParameters
72+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
73+
74+
## INPUTS
75+
76+
### System.String
77+
### The name of the color or icon theme to remove.
78+
## OUTPUTS
79+
80+
### None.
81+
## NOTES
82+
A theme must not be active in order to be removed.
83+
84+
## RELATED LINKS
85+
86+
[Set-TerminalIconsTheme]()
87+
88+
[Add-TerminalIconsColorTheme]()
89+
90+
[Add-TerminalIconsIconTheme]()
91+
92+
[Get-TerminalIconsTheme]()
93+

0 commit comments

Comments
 (0)