-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuick-Note.psm1
More file actions
99 lines (79 loc) · 2.13 KB
/
Quick-Note.psm1
File metadata and controls
99 lines (79 loc) · 2.13 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
function Quick-Note {
param(
[string] $a,
[switch] $x)
#Initializes cache if first run
if(!$notes)
{
$global:notes = New-Object System.Collections.ArrayList
}
#Clears cache
if($x)
{
ClearNotes
}
#Appends new note to cache
if ($a)
{
AppendNote($a)
}
#Print cache to console
PrintNotes
<#
.SYNOPSIS
Store and view quick text notes in the Powershell console.
.DESCRIPTION
This module caches text notes appending them to a persistent variable in the current Powershell session.
It allows to clear, append and display the note cache on the Powershell console.
The note cache will be cleared when the Powershell session ends.
To use import as a PS module:
PS> Import-Module -Name {path}/Quick-Note.psm1
.PARAMETER a
String to append to current note cache.
.PARAMETER x
Clear note cache.
.EXAMPLE
PS> Quick-Note -x
.EXAMPLE
PS> Quick-Note -a "Hello world"
.EXAMPLE
PS> Quick-Note
#>
}
function AppendNote($newNoteText)
{
$datetime = Get-Date
$id = $notes.Count + 1
$newnote = New-Object System.Object
$newnote | Add-Member -MemberType NoteProperty -Name Id -Value $id
$newnote | Add-Member -MemberType NoteProperty -Name DateTime -Value $datetime
$newnote | Add-Member -MemberType NoteProperty -Name Note -Value $newNoteText
$notes.Add($newnote)
}
function EditNote($id)
{
#TODO
}
function DeleteNote($id)
{
#TODO
}
#Print note cache to screen
function PrintNotes()
{
$spacer = "༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻༻"
$originalForegroundColor = $host.ui.RawUI.ForegroundColor
$host.ui.RawUI.ForegroundColor = “Magenta”
Write-Host $spacer
$notes | Format-Table Id, @{Label="DateTime"; Expression={$_.DateTime.ToString("MM/dd HH:mm")}}, Note
Write-Host $spacer
$host.ui.RawUI.ForegroundColor = $originalForegroundColor
}
function ClearNotes()
{
Clear-Variable -Scope Global -Name notes
}
#Making module alias available
New-Alias -Name cn -Value Quick-Note
#Exposing module main function
Export-ModuleMember -Function Quick-Note -Alias cn