Public/Set/Set-ISETheme.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function Set-ISETheme {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions','')]
    [cmdletbinding()]
    Param(
        [Parameter(Mandatory=$True,ParameterSetName='FromFile',ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [string]$File,

        [Parameter(Mandatory=$True,ParameterSetName='FromReg',ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [string]$ThemeName,

        [Parameter(Mandatory=$True,ParameterSetName='FromObj',ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [object]$ThemeObject
    )

    Begin{}

    Process {
        #-Determine if a file, object or theme name was passed and retrieve the theme accordingly
        If ($ThemeObject) {
           $xmlObjects = $ThemeObject 
        } Else {
            If ($File) {
                $xmlObjects = Get-ISETheme -File $File
            } Else {
                $xmlObjects = Get-ISETheme -ThemeName $ThemeName
            }
        }
        
        #-Set Base colors
        $xmlObjects | ForEach-Object {
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('ErrorForegroundColor')) {$psISE.Options.ErrorForegroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('ErrorBackgroundColor')) {$psISE.Options.ErrorBackgroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('WarningForegroundColor')) {$psISE.Options.WarningForegroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('WarningBackgroundColor')) {$psISE.Options.WarningBackgroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('VerboseForegroundColor')) {$psISE.Options.VerboseForegroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('VerboseBackgroundColor')) {$psISE.Options.VerboseBackgroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('DebugForegroundColor')) {$psISE.Options.DebugForegroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('DebugBackgroundColor')) {$psISE.Options.DebugBackgroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('ConsolePaneBackgroundColor')) {$psISE.Options.ConsolePaneBackgroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('ConsolePaneTextBackgroundColor')) {$psISE.Options.ConsolePaneTextBackgroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('ConsolePaneForegroundColor')) {$psISE.Options.ConsolePaneForegroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('ScriptPaneBackgroundColor')) {$psISE.Options.ScriptPaneBackgroundColor = $_.Hex}
            If ($_.Class.Contains('Base') -and $_.Attribute.Contains('ScriptPaneForegroundColor')) {$psISE.Options.ScriptPaneForegroundColor = $_.Hex}
        }
        
        $xmlObjects | ForEach-Object {
            #-Set TokenColors
            If ($_.Class -eq 'TokenColors') {
                $psISE.Options.TokenColors.item($_.Attribute) = $_.Hex
            }
        
            #-Set ConsoleTokenColors
            If ($_.Class -eq 'ConsoleTokenColors') {
                $psISE.Options.ConsoleTokenColors.item($_.Attribute) = $_.Hex
            }
       
            #-Set XmlTokenColors
            If ($_.Class.Contains('XmlTokenColors')) {
                If ($_.Attribute.Length -gt 2) {
                    $psISE.Options.XmlTokenColors.item($_.Attribute) = $_.Hex #[$_.Attribute] = $_.Hex
                }
            }

            #-Set Font
            If ($_.Class.Contains('Other') -and !$ThemeObject) {
                $psISE.Options.FontName = $_.FontFamily
                $psISE.Options.FontSize = $_.FontSize
            }
        }
    }
    End{}
    <#
     .SYNOPSIS
      Applies ISE theme to current session
 
  .DESCRIPTION
   Applies ISE theme to current session
 
  .PARAMETER File
   An ISE theme xml filename
 
   .PARAMETER ThemeName
   The name of an ISE theme stored in the registry
 
        .EXAMPLE
   PS C:\> Get-FileName | Set-ISETheme
 
            Gets the ISE theme information from the supplied xml file and assigns it to Theme
 
  .NOTES
            Part of the ISEColorThemeCmdlets.ps1 Script by Jeff Pollock
            http://Lifeinpowerhsell.blogspot.com
            http://gallery.technet.microsoft.com/ISE-Color-Theme-Cmdlets-24905f9e
 #>


}