forked from stcu/SharedScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-VSCodeSetting.ps1
More file actions
57 lines (44 loc) · 1.38 KB
/
Copy pathGet-VSCodeSetting.ps1
File metadata and controls
57 lines (44 loc) · 1.38 KB
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
<#
.SYNOPSIS
Sets a VSCode setting.
.OUTPUTS
System.String, System.Double, System.Int32, System.Boolean depending on VS Code JSON value type.
.LINK
https://code.visualstudio.com/docs/getstarted/settings
.LINK
Get-VSCodeSettingsFile.ps1
.LINK
ConvertFrom-Json
.LINK
Get-Content
.EXAMPLE
Get-VSCodeSetting.ps1 gitlens.advanced.messages/suppressShowKeyBindingsNotice
True
.EXAMPLE
Get-VSCodeSetting.ps1 powershell.codeFormatting.preset -Workspace
Allman
.EXAMPLE
Get-VSCodeSetting.ps1 workbench.colorTheme -Workspace
PowerShell ISE
#>
[CmdletBinding()][OutputType([string],[double],[int],[bool])] Param(
# The name of the setting to set, use / as a path separator for deeper structures.
[Parameter(Position=0,Mandatory=$true)][string] $Name,
# Indicates that the current workspace settings should be
[switch] $Workspace
)
$UnescapedPathSeparator = "(?<=(?:\A|[^\\])(?:\\\\)*)/"
$nameSegment,$path = ($Name -split $UnescapedPathSeparator) -replace '(?s)\\(.)','$1'
${settings.json} = Get-VSCodeSettingsFile.ps1 -Workspace:$Workspace
$property = Get-Content ${settings.json} -Raw |ConvertFrom-Json
while($nameSegment)
{
if(!$property.PSObject.Properties.Match($nameSegment,'NoteProperty').Count)
{
Write-Verbose "VSCode setting not found: $Name"
return $null
}
$property = $property.$nameSegment
$nameSegment,$path = $path
}
$property