|
| 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 | +} |
0 commit comments