1
1
# enable verbose messaging in the psm1 file
2
- if ($myinvocation .line -match " -verbose" ) {
3
- $VerbosePreference = " continue"
2
+ if ($MyInvocation .line -match ' -verbose' ) {
3
+ $VerbosePreference = ' continue'
4
4
}
5
- Write-Verbose " Loading public functions"
5
+ Write-Verbose ' Loading public functions'
6
6
7
7
# exclude files that have special requirements
8
8
Get-ChildItem - Path $PSScriptRoot \functions\* .ps1 - Exclude ' Get-MyCounter.ps1' , ' Get-FileExtensionInfo.ps1' |
9
9
ForEach-Object - Process {
10
- Write-Verbose $_.fullname
10
+ Write-Verbose $_.FullName
11
11
. $_.FullName
12
12
}
13
13
14
- Write-Verbose " Loading Windows-specific commands"
14
+ Write-Verbose ' Loading Windows-specific commands'
15
15
if ($IsWindows -OR ($PSEdition -eq ' Desktop' )) {
16
16
. " $PSScriptRoot \functions\Get-MyCounter.ps1"
17
17
}
18
18
19
19
if ($IsCoreCLR ) {
20
- Write-Verbose " Loading PowerShell 7 specific commands"
20
+ Write-Verbose ' Loading PowerShell 7 specific commands'
21
21
. " $PSScriptRoot \functions\Get-FileExtensionInfo.ps1"
22
22
}
23
23
24
- Write-Verbose " Define the global PSAnsiFileMap variable"
25
- $json = " psansifilemap.json"
24
+ # load ANSIFile Entry format if user is not using $PSStyle
25
+ if (-Not $PSStyle.FileInfo ) {
26
+ Write-Verbose " Using module PSAnsiFile features"
27
+ Write-Verbose ' Loading PSAnsiFile format files'
28
+ Update-FormatData - AppendPath " $PSScriptRoot \formats\psansifileentry.format.ps1xml"
29
+ Update-FormatData - AppendPath " $PSScriptRoot \formats\filesystem-ansi.format.ps1xml"
26
30
27
- # test for user version in $HOME
28
- $userjson = Join-Path - Path $HOME - ChildPath $json
29
- $modjson = Join-Path - Path $PSScriptRoot - ChildPath $json
31
+ Write-Verbose ' Define the global PSAnsiFileMap variable'
32
+ $json = ' psansifilemap.json'
30
33
31
- if (Test-Path - Path $userjson ) {
32
- $map = $userjson
33
- }
34
- else {
35
- # use the file from this module
36
- $map = $modjson
37
- }
34
+ # test for user version in $HOME
35
+ $UserJSON = Join-Path - Path $HOME - ChildPath $json
36
+ $moduleJSON = Join-Path - Path $PSScriptRoot - ChildPath $json
38
37
39
- # ConvertFrom-Json doesn't write simple objects to the pipeline in Windows PowerShell so I
40
- # need to process the results individually.
41
- $mapData = [System.Collections.Generic.List [object ]]::new()
38
+ if (Test-Path - Path $UserJSON ) {
39
+ $map = $UserJSON
40
+ }
41
+ else {
42
+ # use the file from this module
43
+ $map = $moduleJSON
44
+ }
42
45
43
- Get-Content - Path $map | ConvertFrom-Json | ForEach-Object { $_ } | ForEach-Object {
44
- $entry = [pscustomobject ]@ {
45
- PSTypeName = " PSAnsiFileEntry"
46
- Description = $_.description
47
- Pattern = $_.pattern
48
- Ansi = $_.ansi
46
+ # ConvertFrom-Json doesn't write simple objects to the pipeline in Windows PowerShell so I
47
+ # need to process the results individually.
48
+ $mapData = [System.Collections.Generic.List [object ]]::new()
49
+
50
+ Get-Content - Path $map | ConvertFrom-Json | ForEach-Object { $_ } | ForEach-Object {
51
+ $entry = [PSCustomObject ]@ {
52
+ PSTypeName = ' PSAnsiFileEntry'
53
+ Description = $_.description
54
+ Pattern = $_.pattern
55
+ Ansi = $_.ansi
56
+ }
57
+ $mapData.Add ($entry )
49
58
}
50
- $mapData.Add ($entry )
51
- }
52
- Set-Variable - Name PSAnsiFileMap - Value $mapdata - Scope Global
59
+ Set-Variable - Name PSAnsiFileMap - Value $mapData - Scope Global
60
+ } # load PSAnsiFile features
53
61
54
- Write-Verbose " Define special character map"
62
+ Write-Verbose ' Define special character map'
55
63
$global :PSSpecialChar = @ {
56
64
FullBlock = ([char ]0x2588 )
57
65
LightShade = ([char ]0x2591 )
@@ -80,36 +88,37 @@ $global:PSSpecialChar = @{
80
88
}
81
89
82
90
Write-Verbose " Defining the variable `$ PSSamplePath to the samples folder for this module"
83
- $global :PSSamplePath = Join-Path - Path $PSScriptroot - ChildPath Samples
91
+ $global :PSSamplePath = Join-Path - Path $PSScriptRoot - ChildPath Samples
84
92
85
- Write-Verbose " Add ToDo options to the ISE or VS Code"
93
+ # region editor integrations
94
+ Write-Verbose ' Add ToDo options to the ISE or VS Code'
86
95
if ($psEditor ) {
87
- Write-Verbose " Defining VSCode additions"
96
+ Write-Verbose ' Defining VSCode additions'
88
97
$sb = {
89
98
Param ($context = $psEditor.GetEditorContext () )
90
- $prompt = " What do you need to do?"
91
- $title = " To Do"
99
+ $prompt = ' What do you need to do?'
100
+ $title = ' To Do'
92
101
$item = Invoke-InputBox - Title $title - Prompt $prompt
93
102
$todo = " # TODO: $item [$ ( Get-Date ) ]"
94
103
$context.CurrentFile.InsertText ($todo )
95
104
}
96
105
$rParams = @ {
97
- Name = " Insert.ToDo"
98
- DisplayName = " Insert ToDo"
106
+ Name = ' Insert.ToDo'
107
+ DisplayName = ' Insert ToDo'
99
108
ScriptBlock = $sb
100
109
SuppressOutput = $false
101
110
}
102
111
Register-EditorCommand @rParams
103
112
104
- Write-Verbose " Adding Set-LocationToFile"
113
+ Write-Verbose ' Adding Set-LocationToFile'
105
114
Function Set-LocationToFile {
106
115
# set location to directory of current file
107
116
[CmdletBinding ()]
108
- [alias (" sd " , " jmp" )]
109
- [outputtype ( " none" )]
117
+ [alias (' sd ' , ' jmp' )]
118
+ [OutputType ( ' none' )]
110
119
Param ()
111
120
112
- if ($host.name -match " Code" ) {
121
+ if ($host.name -match ' Code' ) {
113
122
114
123
$context = $psEditor.GetEditorContext ()
115
124
$thispath = $context.CurrentFile.Path
@@ -121,56 +130,56 @@ if ($psEditor) {
121
130
Clear-Host
122
131
}
123
132
else {
124
- Write-Warning " This command must be run in the VS Code integrated PowerShell terminal."
133
+ Write-Warning ' This command must be run in the VS Code integrated PowerShell terminal.'
125
134
}
126
135
}
127
136
} # VSCode
128
- elseif ($psise ) {
129
- Write-Verbose " Defining ISE additions"
137
+ elseif ($psIse ) {
138
+ Write-Verbose ' Defining ISE additions'
130
139
131
- if ($psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.DisplayName -notcontains " ToDo" ) {
140
+ if ($psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.DisplayName -NotContains ' ToDo' ) {
132
141
133
142
$action = {
134
- $prompt = " What do you need to do?"
135
- $title = " To Do"
143
+ $prompt = ' What do you need to do?'
144
+ $title = ' To Do'
136
145
$item = Invoke-InputBox - Title $title - Prompt $prompt
137
146
$todo = " # [$ ( Get-Date ) ] TODO: $item "
138
147
$psise.CurrentFile.Editor.InsertText ($todo )
139
148
# jump cursor to the end
140
149
$psise.CurrentFile.editor.SetCaretPosition ($psise.CurrentFile.Editor.CaretLine , $psise.CurrentFile.Editor.CaretColumn )
141
150
}
142
151
# add the action to the Add-Ons menu
143
- $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add (" ToDo" , $Action , " Ctrl+Alt+2" ) | Out-Null
152
+ $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add (' ToDo' , $Action , ' Ctrl+Alt+2' ) | Out-Null
144
153
}
145
154
146
155
Function Set-LocationToFile {
147
156
[cmdletbinding ()]
148
- [alias (" sd " , " jmp" )]
149
- [OutputType (" none" )]
157
+ [alias (' sd ' , ' jmp' )]
158
+ [OutputType (' none' )]
150
159
Param ()
151
160
152
- if ($host.name -match " ISE" ) {
161
+ if ($host.name -match ' ISE' ) {
153
162
$path = Split-Path - Path $psISE.CurrentFile.FullPath
154
163
Set-Location - Path $path
155
164
Clear-Host
156
165
}
157
166
Else {
158
- Write-Warning " This command must be run the the PowerShell ISE."
167
+ Write-Warning ' This command must be run the the PowerShell ISE.'
159
168
}
160
169
}
161
170
}
162
-
171
+ # endregion
163
172
164
173
# define a function to open the PDF version of the README and other documentation
165
174
Function Open-PSScriptToolsHelp {
166
175
[cmdletbinding ()]
167
176
Param ()
168
- Write-Verbose " Starting $ ( $myinvocation .mycommand ) "
177
+ Write-Verbose " Starting $ ( $MyInvocation .MyCommand ) "
169
178
$pdf = Join-Path - Path $PSScriptRoot - ChildPath PSScriptToolsManual.pdf
170
179
Write-Verbose " Testing the path $pdf "
171
180
if (Test-Path - Path $pdf ) {
172
181
Try {
173
- Write-Verbose " Invoking the PDF"
182
+ Write-Verbose ' Invoking the PDF'
174
183
Invoke-Item - Path $pdf - ErrorAction Stop
175
184
}
176
185
Catch {
@@ -180,7 +189,7 @@ Function Open-PSScriptToolsHelp {
180
189
else {
181
190
Write-Warning " Can't find $pdf ."
182
191
}
183
- Write-Verbose " Ending $ ( $myinvocation .MyCommand ) "
192
+ Write-Verbose " Ending $ ( $MyInvocation .MyCommand ) "
184
193
}
185
194
186
- $VerbosePreference = " silentlyContinue "
195
+ $VerbosePreference = ' SilentlyContinue '
0 commit comments