-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathConfigure_Terminal.ps1
405 lines (358 loc) · 12.3 KB
/
Configure_Terminal.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#Requires -RunAsAdministrator
# https://docs.microsoft.com/en-us/windows/terminal/
# https://github.com/microsoft/terminal/releases
Clear-Host
if ($psISE)
{
exit
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if (-not (Test-Path -Path "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"))
{
Start-Process -FilePath wt
Write-Verbose -Message "Restart the PowerShell session and re-run the script" -Verbose
exit
}
try
{
$Terminal = Get-Content -Path "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" -Encoding UTF8 -Force | ConvertFrom-Json
}
catch [System.Exception]
{
Write-Warning -Message "JSON is not valid!"
Invoke-Item -Path "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState"
exit
}
#region General
# Copy
if (-not ($Terminal.actions | Where-Object -FilterScript {$_.command -eq "copy"} | Where-Object -FilterScript {$_.keys -eq "ctrl+c"}))
{
$closeTab = [PSCustomObject]@{
"command" = "copy"
"keys" = "ctrl+c"
}
$Terminal.actions += $closeTab
}
# Paste
if (-not ($Terminal.actions | Where-Object -FilterScript {$_.command -eq "paste"} | Where-Object -FilterScript {$_.keys -eq "ctrl+v"}))
{
$closeTab = [PSCustomObject]@{
"command" = "paste"
"keys" = "ctrl+v"
}
$Terminal.actions += $closeTab
}
# Close tab
if (-not ($Terminal.actions | Where-Object -FilterScript {$_.command -eq "closeTab"} | Where-Object -FilterScript {$_.keys -eq "ctrl+w"}))
{
$closeTab = [PSCustomObject]@{
"command" = "closeTab"
"keys" = "ctrl+w"
}
$Terminal.actions += $closeTab
}
# New tab
if (-not ($Terminal.actions | Where-Object -FilterScript {$_.command -eq "newTab"} | Where-Object -FilterScript {$_.keys -eq "ctrl+t"}))
{
$newTab = [PSCustomObject]@{
"command" = "newTab"
"keys" = "ctrl+t"
}
$Terminal.actions += $newTab
}
# Find
if (-not ($Terminal.actions | Where-Object -FilterScript {$_.command -eq "find"} | Where-Object -FilterScript {$_.keys -eq "ctrl+f"}))
{
$find = [PSCustomObject]@{
"command" = "find"
"keys" = "ctrl+f"
}
$Terminal.actions += $find
}
# Split pane
if (-not ($Terminal.actions | Where-Object -FilterScript {$_.command.action -eq "splitPane"} | Where-Object -FilterScript {$_.command.split -eq "auto"} | Where-Object -FilterScript {$_.command.splitMode -eq "duplicate"}))
{
$split = [PSCustomObject]@{
"action" = "splitPane"
"split" = "auto"
"splitMode" = "duplicate"
}
$splitPane = [PSCustomObject]@{
"command" = $split
"keys" = "ctrl+shift+d"
}
$Terminal.actions += $splitPane
}
# No confirmation when closing all tabs
if ($Terminal.confirmCloseAllTabs)
{
$Terminal.confirmCloseAllTabs = $false
}
else
{
$Terminal | Add-Member -Name confirmCloseAllTabs -MemberType NoteProperty -Value $false -Force
}
# Set default profile on PowerShell
if ($Terminal.defaultProfile)
{
$Terminal.defaultProfile = "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}"
}
else
{
$Terminal | Add-Member -Name defaultProfile -MemberType NoteProperty -Value "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}" -Force
}
# Show tabs in title bar
if ($Terminal.showTabsInTitlebar)
{
$Terminal.showTabsInTitlebar = $false
}
else
{
$Terminal | Add-Member -Name showTabsInTitlebar -MemberType NoteProperty -Value $false -Force
}
# Do not restore previous tabs and panes after relaunching
if ($Terminal.firstWindowPreference)
{
$Terminal.firstWindowPreference = "defaultProfile"
}
else
{
$Terminal | Add-Member -Name firstWindowPreference -MemberType NoteProperty -Value "defaultProfile" -Force
}
#endregion General
#region defaults
# Set Windows95.gif as a background image
# https://github.com/farag2/Windows_Terminal
if (-not (Test-Path -Path "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState\Windows95.gif"))
{
$Parameters = @{
Uri = "https://raw.githubusercontent.com/farag2/Windows_Terminal/main/Windows95.gif"
OutFile = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState\Windows95.gif"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
}
if ($Terminal.profiles.defaults.backgroundImage)
{
$Terminal.profiles.defaults.backgroundImage = "ms-appdata:///roaming/Windows95.gif"
}
else
{
$Terminal.profiles.defaults | Add-Member -Name backgroundImage -MemberType NoteProperty -Value "ms-appdata:///roaming/Windows95.gif" -Force
}
# Background image alignment
if ($Terminal.profiles.defaults.backgroundImageAlignment)
{
$Terminal.profiles.defaults.backgroundImageAlignment = "bottomRight"
}
else
{
$Terminal.profiles.defaults | Add-Member -Name backgroundImageAlignment -MemberType NoteProperty -Value bottomRight -Force
}
# Background image opacity
$Value = 0.3
if ($Terminal.profiles.defaults.backgroundImageOpacity)
{
$Terminal.profiles.defaults.backgroundImageOpacity = $Value
}
else
{
$Terminal.profiles.defaults | Add-Member -Name backgroundImageOpacity -MemberType NoteProperty -Value 0.3 -Force
}
# Background image stretch mode
if ($Terminal.profiles.defaults.backgroundImageStretchMode)
{
$Terminal.profiles.defaults.backgroundImageStretchMode = "none"
}
else
{
$Terminal.profiles.defaults | Add-Member -Name backgroundImageStretchMode -MemberType NoteProperty -Value none -Force
}
# Starting directory
$DesktopFolder = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop
if ($Terminal.profiles.defaults.startingDirectory)
{
$Terminal.profiles.defaults.startingDirectory = $DesktopFolder
}
else
{
$Terminal.profiles.defaults | Add-Member -Name startingDirectory -MemberType NoteProperty -Value $DesktopFolder -Force
}
# Use acrylic
if ($Terminal.profiles.defaults.useAcrylic)
{
$Terminal.profiles.defaults.useAcrylic = $true
}
else
{
$Terminal.profiles.defaults | Add-Member -Name useAcrylic -MemberType NoteProperty -Value $true -Force
}
# Acrylic opacity
if ($Terminal.useAcrylicInTabRow)
{
$Terminal.useAcrylicInTabRow = $true
}
else
{
$Terminal | Add-Member -Name useAcrylicInTabRow -MemberType NoteProperty -Value $true -Force
}
# Show acrylic in tab row
if ($Terminal.profiles.defaults.useAcrylic)
{
$Terminal.profiles.defaults.useAcrylic = $true
}
else
{
$Terminal.profiles.defaults | Add-Member -Name useAcrylic -MemberType NoteProperty -Value $true -Force
}
# Run profile as Administrator by default
if ($Terminal.profiles.defaults.elevate)
{
$Terminal.profiles.defaults.elevate = $true
}
else
{
$Terminal.profiles.defaults | Add-Member -MemberType NoteProperty -Name elevate -Value $true -Force
}
# Run profile as Administrator by default
if ($Terminal.profiles.defaults.experimental.repositionCursorWithMouse)
{
$Terminal.profiles.defaults.experimental.repositionCursorWithMouse = $true
}
else
{
$Terminal.profiles.defaults | Add-Member -MemberType NoteProperty -Name experimental.repositionCursorWithMouse -Value $true -Force
}
# Set "FiraCode NF" as a default font
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
if ((New-Object -TypeName System.Drawing.Text.InstalledFontCollection).Families.Name -contains "FiraCode NF")
{
if ($Terminal.profiles.defaults.font.face)
{
$Terminal.profiles.defaults.font.face = "FiraCode Nerd Font Mono Retina"
}
else
{
$Terminal.profiles.defaults | Add-Member -Name font -MemberType NoteProperty -Value @{face = "FiraCode Nerd Font Mono Retina"} -Force
}
}
# Remove trailing white-space in rectangular selection
if ($Terminal.trimBlockSelection)
{
$Terminal.trimBlockSelection = $true
}
else
{
$Terminal | Add-Member -Name trimBlockSelection -MemberType NoteProperty -Value $true -Force
}
# Create new tabs in the most recently used window on this desktop. If there's not an existing window on this virtual desktop, then create a new terminal window
if ($Terminal.windowingBehavior)
{
$Terminal.windowingBehavior = "useExisting"
}
else
{
$Terminal | Add-Member -Name windowingBehavior -MemberType NoteProperty -Value "useExisting" -Force
}
#endregion defaults
#region Azure
# Hide Azure
if (($Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{b453ae62-4e3d-5e58-b989-0a998ec441b8}"}).hidden)
{
($Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{b453ae62-4e3d-5e58-b989-0a998ec441b8}"}).hidden = $true
}
else
{
$Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{b453ae62-4e3d-5e58-b989-0a998ec441b8}"} | Add-Member -MemberType NoteProperty -Name hidden -Value $true -Force
}
#endregion Azure
#region Powershell Core
if (Test-Path -Path "$env:ProgramFiles\PowerShell\7")
{
# Set the PowerShell 7 tab name
if (($Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{574e775e-4f2a-5b96-ac1e-a2962a402336}"}).name)
{
($Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{574e775e-4f2a-5b96-ac1e-a2962a402336}"}).name = "$([char]::ConvertFromUtf32(0x1F3C6)) PowerShell 7"
}
else
{
$Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{574e775e-4f2a-5b96-ac1e-a2962a402336}"} | Add-Member -MemberType NoteProperty -Name name -Value "$([char]::ConvertFromUtf32(0x1F3C6)) PowerShell 7" -Force
}
# Run this profile as Administrator by default
if (($Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{574e775e-4f2a-5b96-ac1e-a2962a402336}"}).elevate)
{
($Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{574e775e-4f2a-5b96-ac1e-a2962a402336}"}).elevate = $true
}
else
{
$Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{574e775e-4f2a-5b96-ac1e-a2962a402336}"} | Add-Member -MemberType NoteProperty -Name elevate -Value $true -Force
}
}
if (Test-Path -Path "$env:ProgramFiles\PowerShell\7-preview")
{
# Background image stretch mode
if (($Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{a3a2e83a-884a-5379-baa8-16f193a13b21}"}).name)
{
($Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{a3a2e83a-884a-5379-baa8-16f193a13b21}"}).name = "$([char]::ConvertFromUtf32(0x1F437)) PowerShell 7 Preview"
}
else
{
$Terminal.profiles.list | Where-Object -FilterScript {$_.guid -eq "{a3a2e83a-884a-5379-baa8-16f193a13b21}"} | Add-Member -MemberType NoteProperty -Name name -Value "$([char]::ConvertFromUtf32(0x1F437)) PowerShell 7 Preview" -Force
}
}
#endregion Powershell Core
if ($Terminal.theme)
{
$Terminal.theme = "Grace Kelly"
}
else
{
$Terminal | Add-Member -Name theme -MemberType NoteProperty -Value "Grace Kelly" -Force
}
# Create empty array ("themes": [])
if (-not $Terminal.themes)
{
$Terminal | Add-Member -Name themes -MemberType NoteProperty -Value @() -Force
}
if (-not ($Terminal.themes | Where-Object -FilterScript {$_.name -eq "Grace Kelly"}))
{
$Grace_Kelly = [ordered]@{
"name" = "Grace Kelly"
tab = [ordered]@{
"background" = "#00515EFF"
"unfocusedBackground" = "accent"
}
tabRow = [ordered]@{
"background" = "#061612FF"
"unfocusedBackground" = "#061612FF"
}
window = [ordered]@{
"applicationTheme" = "dark"
}
}
$Terminal.themes += $Grace_Kelly
}
# Save in UTF-8 with BOM despite JSON must not has the BOM: https://datatracker.ietf.org/doc/html/rfc8259#section-8.1. Unless Terminal profile names which contains non-latin characters will have "?" instead of titles
ConvertTo-Json -InputObject $Terminal -Depth 4 | Set-Content -Path "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" -Encoding UTF8 -Force
# Set Windows Terminal as default terminal app to host the user interface for command-line applications
$TerminalVersion = (Get-AppxPackage -Name Microsoft.WindowsTerminal).Version
if ([System.Version]$TerminalVersion -ge [System.Version]"1.11")
{
if (-not (Test-Path -Path "HKCU:\Console\%%Startup"))
{
New-Item -Path "HKCU:\Console\%%Startup" -Force
}
# Find the current GUID of Windows Terminal
$PackageFullName = (Get-AppxPackage -Name Microsoft.WindowsTerminal).PackageFullName
Get-ChildItem -Path "HKLM:\SOFTWARE\Classes\PackagedCom\Package\$PackageFullName\Class" | ForEach-Object -Process {
if ((Get-ItemPropertyValue -Path $_.PSPath -Name ServerId) -eq 0)
{
New-ItemProperty -Path "HKCU:\Console\%%Startup" -Name DelegationConsole -PropertyType String -Value $_.PSChildName -Force
}
if ((Get-ItemPropertyValue -Path $_.PSPath -Name ServerId) -eq 1)
{
New-ItemProperty -Path "HKCU:\Console\%%Startup" -Name DelegationTerminal -PropertyType String -Value $_.PSChildName -Force
}
}
}