Skip to content

Commit

Permalink
v2.46.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Mar 3, 2023
1 parent fa59f91 commit 3b7b401
Show file tree
Hide file tree
Showing 133 changed files with 2,968 additions and 1,835 deletions.
846 changes: 423 additions & 423 deletions Archive-ChangeLog.md

Large diffs are not rendered by default.

Binary file modified PSScriptTools.psd1
Binary file not shown.
125 changes: 67 additions & 58 deletions PSScriptTools.psm1
Original file line number Diff line number Diff line change
@@ -1,57 +1,65 @@
#enable verbose messaging in the psm1 file
if ($myinvocation.line -match "-verbose") {
$VerbosePreference = "continue"
if ($MyInvocation.line -match '-verbose') {
$VerbosePreference = 'continue'
}
Write-Verbose "Loading public functions"
Write-Verbose 'Loading public functions'

#exclude files that have special requirements
Get-ChildItem -Path $PSScriptRoot\functions\*.ps1 -Exclude 'Get-MyCounter.ps1', 'Get-FileExtensionInfo.ps1' |
ForEach-Object -Process {
Write-Verbose $_.fullname
Write-Verbose $_.FullName
. $_.FullName
}

Write-Verbose "Loading Windows-specific commands"
Write-Verbose 'Loading Windows-specific commands'
if ($IsWindows -OR ($PSEdition -eq 'Desktop')) {
. "$PSScriptRoot\functions\Get-MyCounter.ps1"
}

if ($IsCoreCLR) {
Write-Verbose "Loading PowerShell 7 specific commands"
Write-Verbose 'Loading PowerShell 7 specific commands'
. "$PSScriptRoot\functions\Get-FileExtensionInfo.ps1"
}

Write-Verbose "Define the global PSAnsiFileMap variable"
$json = "psansifilemap.json"
#load ANSIFile Entry format if user is not using $PSStyle
if (-Not $PSStyle.FileInfo) {
Write-Verbose "Using module PSAnsiFile features"
Write-Verbose 'Loading PSAnsiFile format files'
Update-FormatData -AppendPath "$PSScriptRoot\formats\psansifileentry.format.ps1xml"
Update-FormatData -AppendPath "$PSScriptRoot\formats\filesystem-ansi.format.ps1xml"

#test for user version in $HOME
$userjson = Join-Path -Path $HOME -ChildPath $json
$modjson = Join-Path -Path $PSScriptRoot -ChildPath $json
Write-Verbose 'Define the global PSAnsiFileMap variable'
$json = 'psansifilemap.json'

if (Test-Path -Path $userjson) {
$map = $userjson
}
else {
#use the file from this module
$map = $modjson
}
#test for user version in $HOME
$UserJSON = Join-Path -Path $HOME -ChildPath $json
$moduleJSON = Join-Path -Path $PSScriptRoot -ChildPath $json

#ConvertFrom-Json doesn't write simple objects to the pipeline in Windows PowerShell so I
#need to process the results individually.
$mapData = [System.Collections.Generic.List[object]]::new()
if (Test-Path -Path $UserJSON) {
$map = $UserJSON
}
else {
#use the file from this module
$map = $moduleJSON
}

Get-Content -Path $map | ConvertFrom-Json | ForEach-Object { $_ } | ForEach-Object {
$entry = [pscustomobject]@{
PSTypeName = "PSAnsiFileEntry"
Description = $_.description
Pattern = $_.pattern
Ansi = $_.ansi
#ConvertFrom-Json doesn't write simple objects to the pipeline in Windows PowerShell so I
#need to process the results individually.
$mapData = [System.Collections.Generic.List[object]]::new()

Get-Content -Path $map | ConvertFrom-Json | ForEach-Object { $_ } | ForEach-Object {
$entry = [PSCustomObject]@{
PSTypeName = 'PSAnsiFileEntry'
Description = $_.description
Pattern = $_.pattern
Ansi = $_.ansi
}
$mapData.Add($entry)
}
$mapData.Add($entry)
}
Set-Variable -Name PSAnsiFileMap -Value $mapdata -Scope Global
Set-Variable -Name PSAnsiFileMap -Value $mapData -Scope Global
} #load PSAnsiFile features

Write-Verbose "Define special character map"
Write-Verbose 'Define special character map'
$global:PSSpecialChar = @{
FullBlock = ([char]0x2588)
LightShade = ([char]0x2591)
Expand Down Expand Up @@ -80,36 +88,37 @@ $global:PSSpecialChar = @{
}

Write-Verbose "Defining the variable `$PSSamplePath to the samples folder for this module"
$global:PSSamplePath = Join-Path -Path $PSScriptroot -ChildPath Samples
$global:PSSamplePath = Join-Path -Path $PSScriptRoot -ChildPath Samples

Write-Verbose "Add ToDo options to the ISE or VS Code"
#region editor integrations
Write-Verbose 'Add ToDo options to the ISE or VS Code'
if ($psEditor) {
Write-Verbose "Defining VSCode additions"
Write-Verbose 'Defining VSCode additions'
$sb = {
Param($context = $psEditor.GetEditorContext() )
$prompt = "What do you need to do?"
$title = "To Do"
$prompt = 'What do you need to do?'
$title = 'To Do'
$item = Invoke-InputBox -Title $title -Prompt $prompt
$todo = "# TODO: $item [$(Get-Date)]"
$context.CurrentFile.InsertText($todo)
}
$rParams = @{
Name = "Insert.ToDo"
DisplayName = "Insert ToDo"
Name = 'Insert.ToDo'
DisplayName = 'Insert ToDo'
ScriptBlock = $sb
SuppressOutput = $false
}
Register-EditorCommand @rParams

Write-Verbose "Adding Set-LocationToFile"
Write-Verbose 'Adding Set-LocationToFile'
Function Set-LocationToFile {
#set location to directory of current file
[CmdletBinding()]
[alias("sd", "jmp")]
[outputtype("none")]
[alias('sd', 'jmp')]
[OutputType('none')]
Param ()

if ($host.name -match "Code") {
if ($host.name -match 'Code') {

$context = $psEditor.GetEditorContext()
$thispath = $context.CurrentFile.Path
Expand All @@ -121,56 +130,56 @@ if ($psEditor) {
Clear-Host
}
else {
Write-Warning "This command must be run in the VS Code integrated PowerShell terminal."
Write-Warning 'This command must be run in the VS Code integrated PowerShell terminal.'
}
}
} #VSCode
elseif ($psise) {
Write-Verbose "Defining ISE additions"
elseif ($psIse) {
Write-Verbose 'Defining ISE additions'

if ($psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.DisplayName -notcontains "ToDo") {
if ($psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.DisplayName -NotContains 'ToDo') {

$action = {
$prompt = "What do you need to do?"
$title = "To Do"
$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
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('ToDo', $Action, 'Ctrl+Alt+2' ) | Out-Null
}

Function Set-LocationToFile {
[cmdletbinding()]
[alias("sd", "jmp")]
[OutputType("none")]
[alias('sd', 'jmp')]
[OutputType('none')]
Param()

if ($host.name -match "ISE") {
if ($host.name -match 'ISE') {
$path = Split-Path -Path $psISE.CurrentFile.FullPath
Set-Location -Path $path
Clear-Host
}
Else {
Write-Warning "This command must be run the the PowerShell ISE."
Write-Warning 'This command must be run the the PowerShell ISE.'
}
}
}

#endregion

#define a function to open the PDF version of the README and other documentation
Function Open-PSScriptToolsHelp {
[cmdletbinding()]
Param()
Write-Verbose "Starting $($myinvocation.mycommand)"
Write-Verbose "Starting $($MyInvocation.MyCommand)"
$pdf = Join-Path -Path $PSScriptRoot -ChildPath PSScriptToolsManual.pdf
Write-Verbose "Testing the path $pdf"
if (Test-Path -Path $pdf) {
Try {
Write-Verbose "Invoking the PDF"
Write-Verbose 'Invoking the PDF'
Invoke-Item -Path $pdf -ErrorAction Stop
}
Catch {
Expand All @@ -180,7 +189,7 @@ Function Open-PSScriptToolsHelp {
else {
Write-Warning "Can't find $pdf."
}
Write-Verbose "Ending $($myinvocation.MyCommand)"
Write-Verbose "Ending $($MyInvocation.MyCommand)"
}

$VerbosePreference = "silentlyContinue"
$VerbosePreference = 'SilentlyContinue'
Binary file modified PSScriptToolsManual.pdf
Binary file not shown.
Loading

0 comments on commit 3b7b401

Please sign in to comment.