-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPSCalendar.psm1
79 lines (66 loc) · 2.97 KB
/
PSCalendar.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
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
#functions based on code from Lee Holmes
# http://www.leeholmes.com/blog/2008/12/03/showing-calendars-in-your-oof-messages/
#dot source the calendar functions
Get-Childitem $PSScriptRoot\functions\*.ps1 -Exclude dev.ps1 |
Foreach-Object {
. $_.Fullname
}
#define a hashtable of ANSI escapes to use in the calendar
if ($IsCoreCLR) {
$esc = "`e"
} else {
$esc = [Char]27
}
$PSCalendarConfiguration = @{
Title = "$esc[38;5;3m"
DayOfWeek = "$esc[1;4;36m"
Today = "$esc[91m"
Highlight = "$esc[92m"
}
#define an auto completer for the Month parameter
Register-ArgumentCompleter -CommandName Get-Calendar, Show-Calendar,Get-NCalendar -ParameterName Month -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
#get month names, filtering out blanks
[system.globalization.cultureinfo]::CurrentCulture.dateTimeFormat.monthnames | Where-Object { $_ -match "\w+" -and $_ -match "$WordToComplete" } |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_.Trim(), $_.Trim(), 'ParameterValue', $_)
}
}
#define an auto completer for the Year parameter
Register-ArgumentCompleter -CommandName Get-Calendar, Show-Calendar,Get-NCalendar -ParameterName Year -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
$first = (Get-Date).Year
$last = (Get-Date).AddYears(5).Year
$first..$last |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
#Export appropriate module members based on whether the user is running Windows or not.
If ($IsWindows -OR ($PSEdition -eq 'Desktop')) {
Export-ModuleMember -Function 'Show-PSCalendarHelp','Get-Calendar',
'Show-Calendar', 'Show-GuiCalendar', 'Get-PSCalendarConfiguration',
'Set-PSCalendarConfiguration','Get-NCalendar','Get-MonthName' -Alias 'cal', 'scal', 'gcal', 'ncal'
#define an autocompleter for background color
Register-ArgumentCompleter -CommandName Show-GuiCalendar -ParameterName BackgroundColor -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
Try {
Add-Type -AssemblyName PresentationFramework -ErrorAction Stop
Add-Type -AssemblyName PresentationCore -ErrorAction Stop
[System.Windows.Media.Brushes].GetProperties().Name |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Catch {
#if assemblies can't be loaded don't do anything
}
}
}
else {
Export-ModuleMember -Function 'Show-PSCalendarHelp', 'Get-Calendar',
'Show-Calendar', 'Get-PSCalendarConfiguration',
'Set-PSCalendarConfiguration','Get-MonthName' -Alias scal
}
#use this version in verbose output to reflect module version
$modver = (Test-ModuleManifest $PSScriptroot\PSCalendar.psd1).Version