11# 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'
44}
5- Write-Verbose " Loading public functions"
5+ Write-Verbose ' Loading public functions'
66
77# exclude files that have special requirements
88Get-ChildItem - Path $PSScriptRoot \functions\* .ps1 - Exclude ' Get-MyCounter.ps1' , ' Get-FileExtensionInfo.ps1' |
99ForEach-Object - Process {
10- Write-Verbose $_.fullname
10+ Write-Verbose $_.FullName
1111 . $_.FullName
1212}
1313
14- Write-Verbose " Loading Windows-specific commands"
14+ Write-Verbose ' Loading Windows-specific commands'
1515if ($IsWindows -OR ($PSEdition -eq ' Desktop' )) {
1616 . " $PSScriptRoot \functions\Get-MyCounter.ps1"
1717}
1818
1919if ($IsCoreCLR ) {
20- Write-Verbose " Loading PowerShell 7 specific commands"
20+ Write-Verbose ' Loading PowerShell 7 specific commands'
2121 . " $PSScriptRoot \functions\Get-FileExtensionInfo.ps1"
2222}
2323
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"
2630
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'
3033
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
3837
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+ }
4245
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 )
4958 }
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
5361
54- Write-Verbose " Define special character map"
62+ Write-Verbose ' Define special character map'
5563$global :PSSpecialChar = @ {
5664 FullBlock = ([char ]0x2588 )
5765 LightShade = ([char ]0x2591 )
@@ -80,36 +88,37 @@ $global:PSSpecialChar = @{
8088}
8189
8290Write-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
8492
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'
8695if ($psEditor ) {
87- Write-Verbose " Defining VSCode additions"
96+ Write-Verbose ' Defining VSCode additions'
8897 $sb = {
8998 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'
92101 $item = Invoke-InputBox - Title $title - Prompt $prompt
93102 $todo = " # TODO: $item [$ ( Get-Date ) ]"
94103 $context.CurrentFile.InsertText ($todo )
95104 }
96105 $rParams = @ {
97- Name = " Insert.ToDo"
98- DisplayName = " Insert ToDo"
106+ Name = ' Insert.ToDo'
107+ DisplayName = ' Insert ToDo'
99108 ScriptBlock = $sb
100109 SuppressOutput = $false
101110 }
102111 Register-EditorCommand @rParams
103112
104- Write-Verbose " Adding Set-LocationToFile"
113+ Write-Verbose ' Adding Set-LocationToFile'
105114 Function Set-LocationToFile {
106115 # set location to directory of current file
107116 [CmdletBinding ()]
108- [alias (" sd " , " jmp" )]
109- [outputtype ( " none" )]
117+ [alias (' sd ' , ' jmp' )]
118+ [OutputType ( ' none' )]
110119 Param ()
111120
112- if ($host.name -match " Code" ) {
121+ if ($host.name -match ' Code' ) {
113122
114123 $context = $psEditor.GetEditorContext ()
115124 $thispath = $context.CurrentFile.Path
@@ -121,56 +130,56 @@ if ($psEditor) {
121130 Clear-Host
122131 }
123132 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.'
125134 }
126135 }
127136} # VSCode
128- elseif ($psise ) {
129- Write-Verbose " Defining ISE additions"
137+ elseif ($psIse ) {
138+ Write-Verbose ' Defining ISE additions'
130139
131- if ($psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.DisplayName -notcontains " ToDo" ) {
140+ if ($psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.DisplayName -NotContains ' ToDo' ) {
132141
133142 $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'
136145 $item = Invoke-InputBox - Title $title - Prompt $prompt
137146 $todo = " # [$ ( Get-Date ) ] TODO: $item "
138147 $psise.CurrentFile.Editor.InsertText ($todo )
139148 # jump cursor to the end
140149 $psise.CurrentFile.editor.SetCaretPosition ($psise.CurrentFile.Editor.CaretLine , $psise.CurrentFile.Editor.CaretColumn )
141150 }
142151 # 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
144153 }
145154
146155 Function Set-LocationToFile {
147156 [cmdletbinding ()]
148- [alias (" sd " , " jmp" )]
149- [OutputType (" none" )]
157+ [alias (' sd ' , ' jmp' )]
158+ [OutputType (' none' )]
150159 Param ()
151160
152- if ($host.name -match " ISE" ) {
161+ if ($host.name -match ' ISE' ) {
153162 $path = Split-Path - Path $psISE.CurrentFile.FullPath
154163 Set-Location - Path $path
155164 Clear-Host
156165 }
157166 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.'
159168 }
160169 }
161170}
162-
171+ # endregion
163172
164173# define a function to open the PDF version of the README and other documentation
165174Function Open-PSScriptToolsHelp {
166175 [cmdletbinding ()]
167176 Param ()
168- Write-Verbose " Starting $ ( $myinvocation .mycommand ) "
177+ Write-Verbose " Starting $ ( $MyInvocation .MyCommand ) "
169178 $pdf = Join-Path - Path $PSScriptRoot - ChildPath PSScriptToolsManual.pdf
170179 Write-Verbose " Testing the path $pdf "
171180 if (Test-Path - Path $pdf ) {
172181 Try {
173- Write-Verbose " Invoking the PDF"
182+ Write-Verbose ' Invoking the PDF'
174183 Invoke-Item - Path $pdf - ErrorAction Stop
175184 }
176185 Catch {
@@ -180,7 +189,7 @@ Function Open-PSScriptToolsHelp {
180189 else {
181190 Write-Warning " Can't find $pdf ."
182191 }
183- Write-Verbose " Ending $ ( $myinvocation .MyCommand ) "
192+ Write-Verbose " Ending $ ( $MyInvocation .MyCommand ) "
184193}
185194
186- $VerbosePreference = " silentlyContinue "
195+ $VerbosePreference = ' SilentlyContinue '
0 commit comments