forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPSScriptTools.psm1
More file actions
44 lines (38 loc) · 1.44 KB
/
PSScriptTools.psm1
File metadata and controls
44 lines (38 loc) · 1.44 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
#enable verbose messaging in the psm1 file
if ($myinvocation.line -match "-verbose") {
$VerbosePreference = "continue"
}
Write-Verbose "Loading public functions"
Get-ChildItem -path $PSScriptRoot\functions\*.ps1 | foreach-object -process {
write-verbose $_.fullname
. $_.FullName
}
#add ToDo options to the ISE or VS Code
if ($psEditor) {
write-verbose "Defining VSCode additions"
$sb = {
Param(
[Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context
)
$prompt = "What do you need to do?"
$title = "To Do"
$item = Invoke-Inputbox -Title $title -Prompt $prompt
$todo = "# [$(Get-Date)] TODO: $item"
$context.CurrentFile.InsertText($todo)
}
Register-EditorCommand -Name "Insert.ToDo" -DisplayName "Insert ToDo" -ScriptBlock $sb -SuppressOutput
}
elseif ($psise) {
write-verbose "Defining ISE additions"
$action = {
$prompt = "What do you need to do?"
$title = "To Do"
$item = Invoke-Inputbox -Title $title -Prompt $prompt
$todo = "# [$(Get-Date)] TODO: $item"
$psise.CurrentFile.Editor.InsertText($todo)
#jump cursor to the end
$psise.CurrentFile.editor.SetCaretPosition($psise.CurrentFile.Editor.CaretLine, $psise.CurrentFile.Editor.CaretColumn)
}
#add the action to the Add-Ons menu
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("ToDo", $Action, "Ctrl+Alt+2" ) | Out-Null
}