-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPSClock.psm1
54 lines (45 loc) · 2.16 KB
/
PSClock.psm1
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
#Turn on additional verbose messaging when importing the module
if ($MyInvocation.line -match "-verbose") {
$VerbosePreference = "Continue"
$manifest = Import-PowerShellDataFile $PSScriptRoot\PSClock.psd1
Write-Verbose "Importing module version $($manifest.ModuleVersion)"
}
Write-Verbose "Sourcing functions: "
Get-ChildItem -Path $PSScriptRoot\functions\*.ps1 |
ForEach-Object {
Write-Verbose $_.FullName
. $_.FullName
}
#the path for Save-PSClock
$SavePath = Join-Path -Path $home -ChildPath PSClockSettings.xml
Write-Verbose "Using save path $SavePath"
#this module should never even run on a non-Windows platform.
#This code is a failsafe.
if ($IsWindows -OR ($PSEdition -eq 'desktop')) {
Write-Verbose "Registering argument completer for FontFamily"
Register-ArgumentCompleter -CommandName 'Start-PSClock', 'Set-PSClock' -ParameterName 'FontFamily' -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
[System.Drawing.Text.InstalledFontCollection]::new().Families.Name |
Where-Object { $_ -match "^$($WordToComplete)" } |
ForEach-Object {
# completion text,listItem text,result type,Tooltip
[System.Management.Automation.CompletionResult]::new("'$($_)'", $_, 'ParameterValue', $_)
}
}
Write-Verbose "Registering argument completer for Color"
Register-ArgumentCompleter -CommandName 'Start-PSClock', 'Set-PSClock' -ParameterName 'Color' -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
[System.Drawing.Brushes].GetProperties().name | Select-Object -Skip 1 |
Where-Object { $_ -match "^$($WordToComplete)" } |
ForEach-Object {
#show the color name using the color
$ansi = Get-RGB $_ | Convert-RGBtoAnsi
[String]$show = "$ansi$($_)$([char]27)[0m"
# completion text,listItem text,result type,Tooltip
[System.Management.Automation.CompletionResult]::new("'$($_)'", $show, 'ParameterValue', $_)
}
}
}
if ($VerbosePreference -eq 'Continue') {
$VerbosePreference = 'SilentlyContinue'
}