This repository has been archived by the owner on Aug 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
WIP-consolefont.ps1
162 lines (142 loc) · 5.86 KB
/
WIP-consolefont.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<#
.SYNOPSIS
Sets the console settings to the specified values and color theme.
.DESCRIPTION
Sets the console settings to the specified values and color theme.
.EXAMPLE
C:\PS> Configure-ConsoleSettings -Theme ConEmu -WindowSize 120,50 `
-FontFace Consolas -FontSize 12
Sets the colors to those used in ConEmu and sets the font and window size.
#>
[CmdletBinding(SupportsShouldProcess)]
param(
# Specify a color theme to choose from.
[Parameter(Mandatory)]
[ValidateSet('Default', 'ConEmu')]
[string]
$Theme,
# Specify the PowerShell arhitecture (x64 or x86). The default is x64.
[Parameter()]
[ValidateSet('x86', 'x64')]
[string]
$Architecture = 'x64',
# Specify the font face.
[Parameter()]
[string]
$FontFace = 'Consolas',
# Specify the font size.
[Parameter()]
[ValidateRange(5, 72)]
[string]
$FontSize,
# If specified, makes the font bold.
[Parameter()]
[switch]
$BoldFont,
# Specify the window size e.g. -WindowSize 120,50
[Parameter()]
[int[]]
$WindowSize,
# Specify the window's opacity in percentage 90 for 90%. Default is 100%
[Parameter()]
[ValidateRange(30, 100)]
[int]
$Opacity = 100
)
begin {
$themes = @{
Default = @{
BackgroundIndex = 0
ForegroundIndex = 7
ColorTable00 = 0x00000000 # Black
ColorTable01 = 0x00800000 # DarkBlue
ColorTable02 = 0x00008000 # DarkGreen
ColorTable03 = 0x00808000 # DarkCyan
ColorTable04 = 0x00000080 # DarkRed
ColorTable05 = 0x00800080 # DarkMagenta
ColorTable06 = 0x00008080 # DarkYellow
ColorTable07 = 0x00C0C0C0 # Gray
ColorTable08 = 0x00808080 # DarkGray
ColorTable09 = 0x00FF0000 # Blue
ColorTable10 = 0x0000FF00 # Green
ColorTable11 = 0x00FFFF00 # Cyan
ColorTable12 = 0x000000FF # Red
ColorTable13 = 0x00FF00FF # Magenta
ColorTable14 = 0X0000FFFF # Yellow
ColorTable15 = 0x00FFFFFF # White
}
ConEmu = @{
BackgroundIndex = 0
ForegroundIndex = 7
ColorTable00 = 0x00201700 # updated - Black
ColorTable01 = 0x00800000
ColorTable02 = 0x00008000
ColorTable03 = 0x00A0A000 # udpated - lightened up DarkCyan
ColorTable04 = 0x000000C0
ColorTable05 = 0x00800080
ColorTable06 = 0x00396070 # updated - DarkYellow
ColorTable07 = 0x00C0C0C0
ColorTable08 = 0x007D7C6F # updated - DarkGray
ColorTable09 = 0x00FF0000
ColorTable10 = 0x0000FF00
ColorTable11 = 0x00FFFF00
ColorTable12 = 0x000000c0
ColorTable13 = 0x00FF00FF
ColorTable14 = 0x0080CAE8 # updated - Yellow
ColorTable15 = 0x00FFFFFF
}
}
function MakeByte([ValidateRange(0,15)][int]$bgIndex, [ValidateRange(0,15)][int]$fgIndex) {
($bgIndex -shl 4) + $fgIndex
}
function MakeDword($left, $right) {
($left -shl 16) + $right
}
}
end {
$regKey = 'HKCU:\Console\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe'
if ($Architecture -eq 'x86') {
$regKey = 'HKCU:\Console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe'
}
#Remove-Item $regKey -EA SilentlyContinue
if (!(Test-Path $regKey)) {
New-Item $regKey > $null
}
if ($PSCmdlet.ShouldProcess($regKey, "Applying theme $Theme")) {
foreach ($kvPair in $themes[$Theme].GetEnumerator()) {
if ($kvPair.Key -notmatch 'ColorTable\d\d') {
continue
}
$PSCmdlet.WriteVerbose("Setting $($kvPair.Key) to $('0x{0:X8}' -f $kvPair.Value)")
New-ItemProperty -Path $regKey -Name $kvPair.Key -Type DWORD -Value $kvPair.Value -Force > $null
}
}
if ($PSCmdlet.ShouldProcess('', "Setting fonts, buffer, screen size, etc")) {
New-ItemProperty $regKey FaceName -Type STRING -Value $FontFace -Force > $null
New-ItemProperty $regKey FontFamily -Type DWORD -Value 0x00000036 -Force > $null
New-ItemProperty $regKey FontWeight -Type DWORD -Value 0x00000190 -Force > $null
New-ItemProperty $regKey HistoryNoDup -Type DWORD -Value 0x00000000 -Force > $null
New-ItemProperty $regKey QuickEdit -Type DWORD -Value 0x00000001 -Force > $null
New-ItemProperty $regKey FilterOnPaste -Type DWORD -Value 0x00000001 -Force > $null
New-ItemProperty $regKey LineSelection -Type DWORD -Value 0x00000001 -Force > $null
$screenColors = MakeByte $themes[$Theme].BackgroundIndex $themes[$Theme].ForegroundIndex
New-ItemProperty $regKey ScreenColors -Type DWORD -Value $screenColors -Force > $null
if ($WindowSize) {
$windowSz = MakeDword $WindowSize[1] $WindowSize[0]
$bufferSz = MakeDword 9999 $WindowSize[0]
New-ItemProperty $regKey ScreenBufferSize -type DWORD -value $bufferSz -Force > $null
New-ItemProperty $regKey WindowSize -type DWORD -value $windowSz -Force > $null
}
if ($FontSize) {
$fontSz = MakeDword $FontSize 0
New-ItemProperty $regKey FontSize -type DWORD -value $fontSz -Force > $null
}
$fontWeight = MakeDword 0 0x190
if ($BoldFont) {
$fontWeight = MakeDword 0 0x2bc
}
New-ItemProperty $regKey FontWeight -type DWORD -value $fontWeight -Force > $null
$opacityVal = MakeDword 0 ([Math]::Ceiling(($Opacity / 100.0) * 256))
New-ItemProperty $regKey WindowAlpha -type DWORD -value $opacityVal -Force > $null
}
}