Skip to content

Commit

Permalink
v1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Aug 1, 2020
1 parent 432635e commit 83d160f
Show file tree
Hide file tree
Showing 18 changed files with 247 additions and 120 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A set of PowerShell functions for managing and working with the [Windows Termina
Install-Module WTToolBox
```

Of course, it is assumed you have `Windows Terminal` installed or planned to. If `Windows Terminal` is not installed, you will get an warning message when you import this module.
Of course, it is assumed you have `Windows Terminal` installed or planned to. If `Windows Terminal` is not installed, you will get a warning message when you import this module.

## Module Commands

Expand All @@ -36,7 +36,7 @@ Install-WTRelease [-preview]

### Displaying Key Bindings

Keeping track of all the possible keyboard shortcuts or keybindings can be difficult. `Get-WTKeyBinding` will go through all defined keybindings and display them. The command writes a custom object to the pipeline for each key binding. To simplify things, the command includes a formatting option so you can easily control how the settings are displayed.
Keeping track of all the possible keyboard shortcuts or keybindings can be difficult. `Get-WTKeyBinding` will go through all defined keybindings and display them. The function writes a custom object to the pipeline for each key binding. To simplify things, the command includes a formatting option so you can easily control how the settings are displayed.

![Get-WTKeyBinding](assets/get-wtkeybinding.png)

Expand All @@ -52,7 +52,7 @@ Use `Get-WTCurrent` to display the settings for the current PowerShell session i

### Tracking Windows Terminal Version

Because `Windows Terminal` can silently update, it may be difficult to know if you are running a new version. You might use the `Test-WTVersion` command in your PowerShell profile script like this:
Because `Windows Terminal` can silently update, it may be awkward to know if you are running a new version. You might use the `Test-WTVersion` command in your PowerShell profile script like this:

```powershell
if ( $env:wt_session -AND Test-WTVersion) {
Expand All @@ -61,7 +61,7 @@ if ( $env:wt_session -AND Test-WTVersion) {
}
```

On a related note, you can also use `Get-WTReleaseNote` which will get the latest release information from the `Windows Terminal` GitHub repository. If you are running PowerShell 7.x, you can pipe the command to `Show-Markdown`.
On a related note, you can also use `Get-WTReleaseNote,` which will get the latest release information from the `Windows Terminal` GitHub repository. If you are running PowerShell 7.x, you can pipe the command to `Show-Markdown`.

```powershell
Get-WTReleaseNote | Show-Markdown -UseBrowser
Expand All @@ -82,7 +82,7 @@ Windows Terminal v1.0.1811.0 v1.0.1811.0 6/30/2020 6:59:57 PM 1.0.1811.0

### Windows Terminal Processes

The `Get-WTProcess` command will get all processes associated with the current Windows Terminal process. The output is a normal `System.Diagnostics.Process` object, but the default formatting has been customized to highlight the current PowerShell process.
The `Get-WTProcess` command will get all processes associated with your Windows Terminal process. The output is a standard `System.Diagnostics.Process` object, but the default formatting has been customized to highlight the current PowerShell process.

![Get-WTProcess](assets/wtprocess-ansi.png)

Expand All @@ -106,11 +106,13 @@ initialCols initialRows
120 30
```

When you import the module, it will also create a variable called `WTDefaultsPath` which points to the `defaults.json` file. This makes it easier if you want to do something with the file like make a copy. If you want to view the file you can use the `Open-WTDefault` command.
When you import the module, it will also create a variable called `$WTDefaultsPath,` which points to the `defaults.json` file. The variable makes it easier if you want to do something with it like make a copy. If you need to view the file, you can use the `Open-WTDefault` command.

> If you have a preview release also installed, this variable will have two objects.
### WTSettings

The last object is a customized version of the data in `settings.json`. The object should make it easier to see your settings.
The last object is a customized version of the data in `settings.json`. `$WTSettings` should make it easier to see your settings.

```powershell
PS C:\> $wtsettings.profiles.list | where-object hidden
Expand Down Expand Up @@ -149,10 +151,10 @@ PS C:\> $WTSettings.refresh()

The method doesn't write anything to the pipeline.

> A quick note on the settings and defaults objects. The JSON standard does not recognize comments, yet they are used in `Windows Terminal` settings files. You can see them with leading // characters. In order to convert the JSON to objects, these comments must be stripped out of the content. This is done with a regular expression. PowerShell 7 is more forgiving if it detects comments. Windows PowerShell will refuse to convert the content from JSON. Although the module has been updated to better handle comments, tt is recommended that if you are using comments, that you insert a space after the leading slashes like this: `// this is a comment`.
> A quick note on the `settings` and `default` objects. The JSON standard does not recognize comments, yet they are used in `Windows Terminal` settings files. You can see them with leading // characters. To avoid errors when converting the JSON to objects, these comments must be stripped out of the content. The clean-up process is done with a regular expression. PowerShell 7 is more forgiving if it detects comments. Windows PowerShell will refuse to convert the content from JSON. Although the module has been updated to better handle comments, it is recommended if you are using comments, that you insert a space after the leading slashes like this: `// this is a comment`.
## Future Versions

If you have any suggestions for enhancements or bug reports, please use the Issues section of this repository.

> *Last updated 2020-07-29 19:10:05Z UTC*
> *Last updated 2020-08-01 19:17:20Z UTC*
2 changes: 1 addition & 1 deletion WTToolBox.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RootModule = 'WTToolBox.psm1'

# Version number of this module.
ModuleVersion = '1.7.0'
ModuleVersion = '1.8.0'

# Supported PSEditions
CompatiblePSEditions = @('Desktop','Core')
Expand Down
61 changes: 45 additions & 16 deletions WTToolBox.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,56 @@ if ($IsWindows -OR $PSEdition -eq 'Desktop') {
(Get-ChildItem $PSScriptRoot\functions\*.ps1).foreach( {.$_.fullname})

Write-Verbose "Testing for Microsoft.WindowsTerminal"
$app = Get-AppxPackage Microsoft.WindowsTerminal
<#
need to take into account that a user might have a preview version also installed
of maybe they are only using the preview version.
8/1/2020 jdh
#>

#use the settings of the currently running Windows Terminal
$app = Get-AppxPackage Microsoft.WindowsTerminal*

if ($app) {
Write-Verbose "Windows Terminal is installed"
Write-Verbose "Windows Terminal is installed"
Write-Verbose "Testing for a current WindowsTerminal Process"
$wt = Get-CimInstance -ClassName Win32_process -filter "ProcessID=$pid"
#validate the parent process is Windows Terminal
$parent = Get-Process -id $wt.parentProcessID

if ($parent.processname -match "WindowsTerminal") {
Write-Verbose "Testing for settings.json"
if (Test-Path -Path "$ENV:Userprofile\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json") {
#Export settings path to a global variable
Write-Verbose "Creating settings variable"
$global:WTSettingsPath = "$ENV:Userprofile\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"

#create a custom object with the settings.json values saved as $WTSettings
AddWTSettingsVariable
}
Write-Verbose "Creating a global variable with defaults"
$defaults = Join-Path -path $app.installlocation -ChildPath defaults.json
$global:WTDefaultsPath = $defaults
$global:WTDefaults = (Get-Content -path $defaults).where({$_ -notmatch "(\/{2})(?=\s+)"}) | ConvertFrom-Json
}
#build path from process path
$wtPath = Split-Path -Path $parent.path
#pull the release name from $wtpath -parsing out version number
$release = Split-Path -path $wtpath -leaf
$trimmed = $Release -replace "_.*_", "_"
$local = Join-Path -path $ENV:Userprofile\AppData\Local\Packages -childpath $trimmed
$jsonPath = Join-Path -path $local -ChildPath "LocalState\settings.json"
Write-Verbose "Using path $jsonPath"
If (Test-Path $jsonPath) {
#Export settings path to a global variable
Write-Verbose "Creating settings variable"
$global:WTSettingsPath = $jsonPath

#create a custom object with the settings.json values saved as $WTSettings
AddWTSettingsVariable

Write-Verbose "Creating a global variable with defaults"
$defaults = Join-Path -path $app.installLocation -ChildPath defaults.json
$global:WTDefaultsPath = $defaults
#need to account for preview and stable releases
$global:WTDefaults = $defaults.foreach( {
$wtPath = $_
(Get-Content -path $_).where( {$_ -notmatch "(\/{2})(?=\s+)"}) | ConvertFrom-Json |
Add-Member -memberType NoteProperty -name DefaultPath -value $wtPath -PassThru
})
} #if json file is found
} #if parent process is WT
} #if $app
else {
Write-Warning "Windows Terminal was not found on this system so not all commands in this module will work."
}
}
} #if Windows
else {
Write-Warning "This module requires a Windows platform."
}
Expand Down
11 changes: 10 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log for WTToolBox

## 1.8.0

+ Modified module commands to take the Preview version into account. It is possible someone will have the preview installed and not the stable release. (Issue #6)
+ Updated the `WTDefaults` global variable to include the path and to accommodate multiple installed releases.
+ Revised `Open-WTDefault` to only run in a Windows Terminal session and to better detect if running under preview or stable release.
+ Added a `-Preview` parameter to `Get-WTReleaseNote` to retrieve the release note from the latest preview.
+ Revised `Get-WTKeyBinding` to handle possible property name change of `keybindings` to `bindings`.
+ Help updates

## 1.7.0

+ Fixed bug in `Install-WTToolbox` that was breaking the installation.
Expand Down Expand Up @@ -47,7 +56,7 @@

## 1.1.0

+ Added `Test-WTVersion`
+ Added `Test-WTVersion`.
+ Modified module to create a global variable `$WTSettings` with a converted version of `settings.json`.
+ Modified module to create a global variable `WTSettingsPath` with the path to the `setting.json` file.
+ Modified module to create a global variable `$WTDefaults` with a converted version of `defaults.json`.
Expand Down
2 changes: 1 addition & 1 deletion docs/Backup-WTSetting.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Backup-WTSetting [[-Limit] <Int32>] [-Destination] <String> [-Passthru] [-WhatIf

## DESCRIPTION

Use this command to create a backup copy of the settings.json file for Windows Terminal. Each backup will be numbered up to the the specified limit. The oldest file will be called settings.bak1.json with the number incrementing for each backup.
Use this command to create a backup copy of the settings.json file for Windows Terminal. Each backup will be numbered up to the specified limit. The oldest file will be called settings.bak1.json with the number incrementing for each backup.

## EXAMPLES

Expand Down
6 changes: 3 additions & 3 deletions docs/Get-WTCurrentRelease.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ schema: 2.0.0

## SYNOPSIS

Get the current Windows Terminal release
Get the current Windows Terminal release.

## SYNTAX

Expand All @@ -19,7 +19,7 @@ Get-WTCurrentRelease [-Preview] [<CommonParameters>]

## DESCRIPTION

This command will give you a summary of the latest Windows Terminal release including locally installed versions. Use the -Preview parameter to check for the latest preview.
This command will give you a summary of the latest Windows Terminal release, including locally installed versions. Use the -Preview parameter to check for the latest preview.

## EXAMPLES

Expand Down Expand Up @@ -69,4 +69,4 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell
## RELATED LINKS
[Test-WTVersion]()
[Test-WTVersion](Test-WTVersion.md)
14 changes: 6 additions & 8 deletions docs/Get-WTKeyBinding.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ schema: 2.0.0
# Get-WTKeyBinding

## SYNOPSIS
Display Windows Terminal key binding information

Display Windows Terminal key binding information.

## SYNTAX

Expand All @@ -18,26 +19,23 @@ Get-WTKeyBinding [[-Format] <String>] [<CommonParameters>]

## DESCRIPTION

Get Windows Terminal key binding settings and display with your choice of formats.
If a keybinding from your settings.json file has the same keys as a default, the
default is overwritten in the output.
Get Windows Terminal key binding settings and display with your choice of formats. If a keybinding from your settings.json file has the same key combination as a default, the default setting is overwritten.

## EXAMPLES

### EXAMPLE 1

```powershell
c:\scripts\Get-WTKeyBindings -format grid
PS C:\Get-WTKeyBinding -format grid
```

This is a PowerShell script so you need to specify the path to the file.
Get Windows Terminal key bindings and display in Out-Gridview.

## PARAMETERS

### -Format

Specify how to display the results.
Possible values are: Table,List,Grid, and None
Specify how to display the results. Possible values are: Table,List,Grid, and None.

This parameter has an alias of 'out'.

Expand Down
4 changes: 2 additions & 2 deletions docs/Get-WTProcess.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ schema: 2.0.0

## SYNOPSIS

Get Windows Terminal processes
Get Windows Terminal processes.

## SYNTAX

Expand All @@ -19,7 +19,7 @@ Get-WTProcess [<CommonParameters>]

## DESCRIPTION

Use this command to get all processes that are part of the current Windows Terminal application. The command output is a regular System.Diagnostics.Process object. However, the default formatting will highlight the current PowerShell process in green text.
Use this command to get all processes that are part of the current Windows Terminal application. The command output is a regular System.Diagnostics.Process object. However, the default formatting will highlight the your PowerShell process in green text.

## EXAMPLES

Expand Down
28 changes: 22 additions & 6 deletions docs/Get-WTReleaseNote.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ schema: 2.0.0

## SYNOPSIS

Get the latest Windows Terminal release information from GitHub
Get the latest Windows Terminal release information from GitHub.

## SYNTAX

```yaml
Get-WTReleaseNote [-AsMarkdown] [-Online] [<CommonParameters>]
Get-WTReleaseNote [-AsMarkdown] [-Online] [-Preview] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -48,12 +48,10 @@ Notes : ## Changes
### Example 2

```powershell
PS C:\> Get-WTReleaseNote -AsMarkdown | Show-Markdown
PS C:\> Get-WTReleaseNote -AsMarkdown -Preview | Show-Markdown
```

In PowerShell 7 you can render the release note as a markdown document and display it as markdown in the console.
Or use the -UseBrowser parameter with Show-Markdown to open the in a web browser.
Referenced GitHub issues should have links to the original issue.
In PowerShell 7, you can render the release note as a markdown document and display it as markdown in the console. This example will show the release note for the most recent preview release. You might also use the -UseBrowser parameter with Show-Markdown to open the in a web browser. Referenced GitHub issues should have links to the original issue.

### Example 3

Expand Down Expand Up @@ -97,6 +95,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Preview
Get the latest preview release.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
Expand All @@ -116,3 +130,5 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/
## RELATED LINKS
[Install-WTRelease](Install-WTRelease.md)
4 changes: 2 additions & 2 deletions docs/Install-WTRelease.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ schema: 2.0.0

## SYNOPSIS

Install the latest Windows Terminal release
Install the latest Windows Terminal release.

## SYNTAX

Expand Down Expand Up @@ -100,4 +100,4 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell
## RELATED LINKS
[Get-WTCurrentRelease]()
[Get-WTCurrentRelease](Get-WTCurrentRelease.md)
2 changes: 1 addition & 1 deletion docs/Open-WTDefault.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ schema: 2.0.0

## SYNOPSIS

Open Windows Terminal default.json file
Open Windows Terminal default.json file.

## SYNTAX

Expand Down
8 changes: 4 additions & 4 deletions docs/Test-WTVersion.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ schema: 2.0.0

## SYNOPSIS

Test if newer version of Windows Terminal is installed.
Test if an updated version of Windows Terminal is installed.

## SYNTAX

Expand All @@ -19,7 +19,7 @@ Test-WTVersion [<CommonParameters>]

## DESCRIPTION

Because Windows Terminal can update in the background, you may not be aware that you are running a newer version. A newer version might offer new features to enable in your settings file or things that you have to change. This command will compare the currently installed version with saved information from the last time the command was run. If the version is newer, this command returns True. The command writes a small json file to $Home.
Because Windows Terminal can update in the background, you may not be aware that you are running a newer version. An updated version might offer new features to enable in your settings file or things that you have to change. This command will compare the currently installed version with saved information from the last time the command was run. If the Windows Terminal version is newer, this command returns True. This function writes a small json file to $Home.

## EXAMPLES

Expand All @@ -42,7 +42,7 @@ PS C:\> if ( $env:wt_session -AND Test-WTVersion) {
}
```

Because Windows Terminal can silently update, it may be difficult to know if you are running a new version. You might use the `Test-WTVersion` command in your PowerShell profile script with this code snippet.
Because Windows Terminal can silently update, it may be awkward to know if you are running a new version. You might use the `Test-WTVersion` command in your PowerShell profile script with this code snippet.

## PARAMETERS

Expand All @@ -64,4 +64,4 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell

## RELATED LINKS

[Get-WTCurrentRelease]()
[Get-WTCurrentRelease](Get-WTCurrentRelease)
Loading

0 comments on commit 83d160f

Please sign in to comment.