This repository was archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathPSColor.psm1
More file actions
159 lines (140 loc) · 5.56 KB
/
PSColor.psm1
File metadata and controls
159 lines (140 loc) · 5.56 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
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
Add-Type -assemblyname System.ServiceProcess
. "$PSScriptRoot\PSColorHelper.ps1"
. "$PSScriptRoot\FileInfo.ps1"
. "$PSScriptRoot\ServiceController.ps1"
. "$PSScriptRoot\MatchInfo.ps1"
. "$PSScriptRoot\ProcessInfo.ps1"
Function Get-PSColorConfig {
[CmdletBinding()]
Param([switch]$Defaults)
#generate path to json color defition file
$PSColorTablePath = Join-Path -Path (Get-ChildItem $profile.CurrentUserCurrentHost).DirectoryName -Childpath PSColorTable.json
if ($Defaults) {
Remove-Item $PSColorTablePath
}
#if the file doesn't exist, generate a template config objcet
if (!(Test-Path $PSColorTablePath)) {
$global:PSColor = @{
Meta = @{
Directory = @{ Color = 'DarkGreen' }
Row = @{ Color = 'Green' }
Divider = @{ Color = 'DarkGreen' }
DirectoryPath = @{ Color = 'Green' }
}
File = @{
Default = @{ Color = 'White' }
Directory = @{ Color = 'Cyan'}
Hidden = @{ Color = 'DarkGray'; Pattern = '^\.' }
Code = @{ Color = 'Magenta'; Pattern = '\.(java|c|cpp|cs|js|css|html|py)$' }
Executable = @{ Color = 'Red'; Pattern = '\.(exe|bat|cmd|py|pl|ps1|psm1|vbs|rb|reg|msi)$' }
Machine = @{ Color = 'Blue'; Pattern = '\.(bin|dll|iso|img|ovf|ova)$' }
Text = @{ Color = 'Yellow'; Pattern = '\.(txt|cfg|conf|ini|csv|log|config|xml|yml|md|markdown)$' }
Image = @{ Color = 'DarkYellow'; Pattern = '\.(jpg|gif|bmp|jpeg|tif|tiff|png|psd|ico)$' }
Audio = @{ Color = 'DarkBlue'; Pattern = '\.(mp3|aif|wav|wma|aif|iff|m4a)$' }
Video = @{ Color = 'DarkCyan'; Pattern = '\.(avi|mov|mpg|mp4|wmv|m4v)$' }
Office = @{ Color = 'DarkRed'; Pattern = '\.(xls|xlsx|xlsm|pdf|docx|doc|ppt|pptx|sdc|sdd|ott|odf|pub|rtf|vsd|vsdx)$' }
Compressed = @{ Color = 'Green'; Pattern = '\.(7z|zip|tar|gz|rar|jar|war)$' }
Temporary = @{ Color = 'Red'; Pattern = '\.(tmp|old|foo|baz|bak)$' }
}
Service = @{
Default = @{ Color = 'White' }
Running = @{ Color = 'DarkGreen' }
Stopped = @{ Color = 'DarkRed' }
}
Match = @{
Default = @{ Color = 'White' }
Path = @{ Color = 'Cyan'}
LineNumber = @{ Color = 'Yellow' }
Line = @{ Color = 'White' }
}
NoMatch = @{
Default = @{ Color = 'White' }
Path = @{ Color = 'Cyan'}
LineNumber = @{ Color = 'Yellow' }
Line = @{ Color = 'White' }
}
}
Write-Warning ("PSColorTable definition file not found at " + $PSColorTablePath + "`r`nCreating default configuration file.`r`nThis only happens if the file doesn't previously exist.")
$global:PSColor | ConvertTo-Json | Out-File $PSColorTablePath
}
else {
if ($global:PSColor) {
Write-Verbose "Overwriting PSColor global variable"
$OMP = get-module -ListAvailable | ?{$_.Name -match "oh-my-posh"}
if ($OMP) {
Write-Warning "oh-my-posh detected, which instances it's own PSColor preference dictionary"
Write-Warning "This should work, but check for compatibility if you experience weirdness."
}
}
$global:PSColor = @{}
Write-Verbose "Loaded PSColors"
(Get-Content $PSColorTablePath | ConvertFrom-Json).psobject.properties | ForEach-Object { $global:PSColor[$_.Name] = $_.Value }
}
}
$script:showHeader=$true
function Out-Default {
[CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=113362', RemotingCapability='None')]
param(
[switch]
${Transcript},
[Parameter(Position=0, ValueFromPipeline=$true)]
[psobject]
${InputObject})
begin
{
try {
$outBuffer = $null
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
{
$PSBoundParameters['OutBuffer'] = 1
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Core\Out-Default', [System.Management.Automation.CommandTypes]::Cmdlet)
$scriptCmd = {& $wrappedCmd @PSBoundParameters }
$steppablePipeline = $scriptCmd.GetSteppablePipeline()
$steppablePipeline.Begin($PSCmdlet)
} catch {
throw
}
}
process
{
try {
if(($_ -is [System.IO.DirectoryInfo]) -or ($_ -is [System.IO.FileInfo]))
{
FileInfo $_
$_ = $null
}
elseif($_ -is [System.ServiceProcess.ServiceController])
{
ServiceController $_
$_ = $null
}
elseif($_ -is [Microsoft.Powershell.Commands.MatchInfo])
{
MatchInfo $_
$_ = $null
}
else {
$steppablePipeline.Process($_)
}
} catch {
throw
}
}
end
{
try {
write-host ""
$script:showHeader=$true
$steppablePipeline.End()
} catch {
throw
}
}
<#
.ForwardHelpTargetName Out-Default
.ForwardHelpCategory Function
#>
}
Export-ModuleMember Out-Default
Export-ModuleMember Get-PSColorConfig