-
Notifications
You must be signed in to change notification settings - Fork 0
/
HyperFocus.psm1
269 lines (240 loc) · 8.5 KB
/
HyperFocus.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# Default file path for the to-do list
$script:defaultFilePath = Join-Path $env:USERPROFILE 'hyperfocus_list.txt'
# Initialize the hyperFocusTasks list as an empty ArrayList if the default file does not exist
$script:hyperFocusTasks = if (Test-Path -Path $script:defaultFilePath) {
Import-HyperFocusTasks $script:defaultFilePath
} else {
New-Object System.Collections.ArrayList
}
<#
.SYNOPSIS
Adds a HyperFocus task.
.DESCRIPTION
Creates and adds a HyperFocus task with the provided details and exports it to the default file.
.PARAMETER item
The description of the task.
.PARAMETER priority
The priority of the task. Default is 'Medium'.
.PARAMETER dueDate
The due date for the task. Optional.
.PARAMETER status
The status of the task. Default is 'Not Started'.
#>
function Add-HyperFocusTask {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$item,
[ValidateSet('High', 'Medium', 'Low')]
[string]$priority = 'Medium',
[string]$dueDate = $null,
[ValidateSet('Not Started', 'In Progress', 'On Hold', 'Completed', 'Cancelled')]
[string]$status = 'Not Started'
)
$hyperfocus = New-Object PSObject -Property @{
'Item' = $item
'Priority' = $priority
'DueDate' = $dueDate
'Status' = $status
}
$script:hyperFocusTasks.Add($hyperfocus) | Out-Null
Export-HyperFocusTasks $script:defaultFilePath
}
<#
.SYNOPSIS
Adds multiple HyperFocus tasks.
.DESCRIPTION
Creates and adds multiple HyperFocus tasks with the provided details and exports them to the default file.
.PARAMETER items
An array of descriptions for the tasks.
.PARAMETER priority
The priority of the tasks. Default is 'Medium'.
.PARAMETER dueDate
The due date for the tasks. Optional.
.PARAMETER status
The status of the tasks. Default is 'Not Started'.
#>
function Add-HyperFocusTasks {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string[]]$items,
[ValidateSet('High', 'Medium', 'Low')]
[string]$priority = 'Medium',
[string]$dueDate = $null,
[ValidateSet('Not Started', 'In Progress', 'On Hold', 'Completed', 'Cancelled')]
[string]$status = 'Not Started'
)
# Create and add HyperFocus tasks for each item
$items | ForEach-Object {
$hyperfocus = New-Object PSObject -Property @{
'Item' = $_
'Priority' = $priority
'DueDate' = $dueDate
'Status' = $status
}
$script:hyperFocusTasks.Add($hyperfocus) | Out-Null
}
Export-HyperFocusTasks $script:defaultFilePath
}
<#
.SYNOPSIS
Removes a HyperFocus task by index.
.DESCRIPTION
Removes a HyperFocus task by the given index and exports the changes to the default file.
.PARAMETER index
The index of the task to remove.
#>
function Remove-HyperFocusTask {
param([int]$index)
if ($index -ge 0 -and $index -lt $script:hyperFocusTasks.Count) {
$script:hyperFocusTasks.RemoveAt($index)
} else {
Write-Host "Invalid index. Please provide an index between 0 and $($script:hyperFocusTasks.Count - 1)."
}
Export-HyperFocusTasks $script:defaultFilePath
}
<#
.SYNOPSIS
Gets HyperFocus tasks with optional sorting and filtering.
.DESCRIPTION
Retrieves HyperFocus tasks and allows sorting by priority and filtering by priority or status.
.PARAMETER sortByPriority
Sort tasks by priority if set to 'true'.
.PARAMETER filterByPriority
Filter tasks by a specific priority.
.PARAMETER filterByStatus
Filter tasks by a specific status.
#>
function Get-HyperFocusTasks {
param(
[string]$sortByPriority,
[string]$filterByPriority,
[string]$filterByStatus
)
$result = $script:hyperFocusTasks
if ($filterByPriority) {
$result = $script:hyperFocusTasks | Where-Object { $_.Priority -eq $filterByPriority }
}
if ($sortByPriority -eq 'true') {
$result = $result | Sort-Object { switch ($_.Priority) { 'High' {1} 'Medium' {2} 'Low' {3} } }
}
for ($i = 0; $i -lt $result.Count; $i++) {
$color = switch ($result[$i].Priority) {
'High' { 'Red' }
'Medium' { 'Yellow' }
'Low' { 'Green' }
default { 'White' }
}
$statusSymbol = switch ($result[$i].Status) {
'Completed' { '✓' }
'In Progress' { '⚙️' }
'Not Started' { '❗' }
'On Hold' { '⏸️' }
default { '' }
}
Write-Host "$($i): $statusSymbol $($result[$i].Item) - Priority: $($result[$i].Priority) - Due Date: $($result[$i].DueDate) - Status: $($result[$i].Status)" -ForegroundColor $color
}
}
<#
.SYNOPSIS
Clears all HyperFocus tasks.
.DESCRIPTION
Clears all HyperFocus tasks from the list.
#>
function Clear-HyperFocusTasks {
$script:hyperFocusTasks.Clear()
}
<#
.SYNOPSIS
Exports HyperFocus tasks to a file.
.DESCRIPTION
Exports all HyperFocus tasks to the specified filename.
.PARAMETER filename
The name of the file to export to.
#>
function Export-HyperFocusTasks {
param([string]$filename)
Remove-Item -Path $filename -ErrorAction Ignore
$script:hyperFocusTasks | ForEach-Object {
"$($_.Item), $($_.Priority), $($_.DueDate), $($_.Status)" | Out-File -FilePath $filename -Append
}
}
<#
.SYNOPSIS
Imports HyperFocus tasks from a file.
.DESCRIPTION
Imports HyperFocus tasks from the specified filename.
.PARAMETER filename
The name of the file to import from.
#>
function Import-HyperFocusTasks {
param([string]$filename)
$content = Get-Content -Path $filename
$content = @($content)
$script:hyperFocusTasks = New-Object System.Collections.ArrayList
$content | ForEach-Object {
$item, $priority, $dueDate, $status = $_.Split(',').Trim()
$hyperfocus = New-Object PSObject -Property @{
'Item' = $item
'Priority' = $priority
'DueDate' = $dueDate
'Status' = $status
}
$script:hyperFocusTasks.Add($hyperfocus) | Out-Null
}
}
<#
.SYNOPSIS
Updates the status of a HyperFocus task by index.
.DESCRIPTION
Updates the status of a HyperFocus task by the given index and exports the changes to the default file.
.PARAMETER index
The index of the task to update.
.PARAMETER status
The new status for the task.
#>
function Update-HyperFocusStatus {
param(
[int]$index,
[string]$status
)
$validStatuses = 'Not Started', 'In Progress', 'On Hold', 'Completed', 'Cancelled'
if ($validStatuses -notcontains $status) {
Write-Host "Invalid status. Please choose one of the following: $($validStatuses -join ', ')"
return
}
if ($index -ge 0 -and $index -lt $script:hyperFocusTasks.Count) {
$script:hyperFocusTasks[$index].Status = $status
Export-HyperFocusTasks $script:defaultFilePath
} else {
Write-Host "Invalid index. Please provide an index between 0 and $($script:hyperFocusTasks.Count - 1)."
}
}
# Default file path for the to-do list
$script:defaultFilePath = Join-Path $env:USERPROFILE 'hyperfocus_list.txt'
# Initialize the to-do list as an empty ArrayList if the default file does not exist
$script:hyperFocusTasks = New-Object System.Collections.ArrayList
# Check if the default file path exists
if (Test-Path -Path $script:defaultFilePath) {
Import-HyperFocusTasks $script:defaultFilePath
} else {
$script:hyperFocusTasks = New-Object System.Collections.ArrayList
}
<#
.SYNOPSIS
Displays available HyperFocus commands.
.DESCRIPTION
Shows the available HyperFocus commands and their usage.
#>
function Show-HyperFocusHelp {
"Available commands:"
"Add-HyperFocusTask '<item>' [priority] [dueDate] [status] - Add a HyperFocus task (enclose item in quotes). Priority can be High, Medium, or Low."
"Get-HyperFocusTasks [sortByPriority] [filterByPriority] [filterByStatus] - Show all HyperFocus tasks. Sort by priority or filter by priority (High, Medium, Low), and status."
"Remove-HyperFocusTask <index> - Remove a HyperFocus task by index."
"Update-HyperFocusStatus <index> <status> - Update the status of a HyperFocus task by index. Status can be Not Started, In Progress, On Hold, Completed, or Cancelled."
"Clear-HyperFocusTasks - Clear all HyperFocus tasks."
"Export-HyperFocusTasks '<filename>' - Export HyperFocus tasks to a file."
"Import-HyperFocusTasks '<filename>' - Import HyperFocus tasks from a file."
"Show-HyperFocusHelp - Display this help menu."
}