From 83d160f77619ec94ed2e681dc4fcbc8d72bbddf8 Mon Sep 17 00:00:00 2001 From: Jeff Hicks Date: Sat, 1 Aug 2020 15:21:27 -0400 Subject: [PATCH] v1.8.0 --- README.md | 20 +++++----- WTToolBox.psd1 | 2 +- WTToolBox.psm1 | 61 +++++++++++++++++++++++-------- changelog.md | 11 +++++- docs/Backup-WTSetting.md | 2 +- docs/Get-WTCurrentRelease.md | 6 +-- docs/Get-WTKeyBinding.md | 14 +++---- docs/Get-WTProcess.md | 4 +- docs/Get-WTReleaseNote.md | 28 +++++++++++--- docs/Install-WTRelease.md | 4 +- docs/Open-WTDefault.md | 2 +- docs/Test-WTVersion.md | 8 ++-- en-us/WTToolBox-help.xml | 65 +++++++++++++++++++++++---------- functions/Get-WTKeybindings.ps1 | 57 +++++++++++++++++++---------- functions/Get-WTProcess.ps1 | 13 +++++-- functions/Get-WTReleaseNote.ps1 | 15 ++++++-- functions/open-wtdefaults.ps1 | 25 ++++++++----- tests/WTToolBox.Tests.ps1 | 30 +++++++++------ 18 files changed, 247 insertions(+), 120 deletions(-) diff --git a/README.md b/README.md index e5a8455..739eaa8 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) @@ -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) { @@ -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 @@ -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) @@ -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 @@ -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* diff --git a/WTToolBox.psd1 b/WTToolBox.psd1 index fea52a7..a68ceda 100644 --- a/WTToolBox.psd1 +++ b/WTToolBox.psd1 @@ -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') diff --git a/WTToolBox.psm1 b/WTToolBox.psm1 index 05926bf..45dba09 100644 --- a/WTToolBox.psm1 +++ b/WTToolBox.psm1 @@ -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." } diff --git a/changelog.md b/changelog.md index 0aeb220..4a44546 100644 --- a/changelog.md +++ b/changelog.md @@ -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. @@ -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`. diff --git a/docs/Backup-WTSetting.md b/docs/Backup-WTSetting.md index ef512d6..abfeb96 100644 --- a/docs/Backup-WTSetting.md +++ b/docs/Backup-WTSetting.md @@ -20,7 +20,7 @@ Backup-WTSetting [[-Limit] ] [-Destination] [-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 diff --git a/docs/Get-WTCurrentRelease.md b/docs/Get-WTCurrentRelease.md index 6b3de9c..394b4e5 100644 --- a/docs/Get-WTCurrentRelease.md +++ b/docs/Get-WTCurrentRelease.md @@ -9,7 +9,7 @@ schema: 2.0.0 ## SYNOPSIS -Get the current Windows Terminal release +Get the current Windows Terminal release. ## SYNTAX @@ -19,7 +19,7 @@ Get-WTCurrentRelease [-Preview] [] ## 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 @@ -69,4 +69,4 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell ## RELATED LINKS -[Test-WTVersion]() +[Test-WTVersion](Test-WTVersion.md) diff --git a/docs/Get-WTKeyBinding.md b/docs/Get-WTKeyBinding.md index 8919ede..4ac7087 100644 --- a/docs/Get-WTKeyBinding.md +++ b/docs/Get-WTKeyBinding.md @@ -8,7 +8,8 @@ schema: 2.0.0 # Get-WTKeyBinding ## SYNOPSIS -Display Windows Terminal key binding information + +Display Windows Terminal key binding information. ## SYNTAX @@ -18,26 +19,23 @@ Get-WTKeyBinding [[-Format] ] [] ## 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'. diff --git a/docs/Get-WTProcess.md b/docs/Get-WTProcess.md index 83852b4..f948612 100644 --- a/docs/Get-WTProcess.md +++ b/docs/Get-WTProcess.md @@ -9,7 +9,7 @@ schema: 2.0.0 ## SYNOPSIS -Get Windows Terminal processes +Get Windows Terminal processes. ## SYNTAX @@ -19,7 +19,7 @@ Get-WTProcess [] ## 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 diff --git a/docs/Get-WTReleaseNote.md b/docs/Get-WTReleaseNote.md index c66ec18..e6caff0 100644 --- a/docs/Get-WTReleaseNote.md +++ b/docs/Get-WTReleaseNote.md @@ -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] [] +Get-WTReleaseNote [-AsMarkdown] [-Online] [-Preview] [] ``` ## DESCRIPTION @@ -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 @@ -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). @@ -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) diff --git a/docs/Install-WTRelease.md b/docs/Install-WTRelease.md index 55e268d..4b551f2 100644 --- a/docs/Install-WTRelease.md +++ b/docs/Install-WTRelease.md @@ -9,7 +9,7 @@ schema: 2.0.0 ## SYNOPSIS -Install the latest Windows Terminal release +Install the latest Windows Terminal release. ## SYNTAX @@ -100,4 +100,4 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell ## RELATED LINKS -[Get-WTCurrentRelease]() +[Get-WTCurrentRelease](Get-WTCurrentRelease.md) diff --git a/docs/Open-WTDefault.md b/docs/Open-WTDefault.md index d577807..6cee9ad 100644 --- a/docs/Open-WTDefault.md +++ b/docs/Open-WTDefault.md @@ -9,7 +9,7 @@ schema: 2.0.0 ## SYNOPSIS -Open Windows Terminal default.json file +Open Windows Terminal default.json file. ## SYNTAX diff --git a/docs/Test-WTVersion.md b/docs/Test-WTVersion.md index 5cd1547..02f13c7 100644 --- a/docs/Test-WTVersion.md +++ b/docs/Test-WTVersion.md @@ -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 @@ -19,7 +19,7 @@ Test-WTVersion [] ## 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 @@ -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 @@ -64,4 +64,4 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell ## RELATED LINKS -[Get-WTCurrentRelease]() +[Get-WTCurrentRelease](Get-WTCurrentRelease) diff --git a/en-us/WTToolBox-help.xml b/en-us/WTToolBox-help.xml index aa5d7de..ebf620a 100644 --- a/en-us/WTToolBox-help.xml +++ b/en-us/WTToolBox-help.xml @@ -10,7 +10,7 @@ - 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. @@ -262,11 +262,11 @@ useAcrylic : True Get WTCurrentRelease - Get the current Windows Terminal release + Get the current Windows Terminal release. - 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. @@ -353,11 +353,11 @@ Windows Terminal v1.0.1811.0 v1.0.1811.0 6/30/2020 6:59:57 PM 1.0.1811.0Get WTKeyBinding - Display Windows Terminal key binding information + Display Windows Terminal key binding information. - 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. @@ -365,7 +365,7 @@ Windows Terminal v1.0.1811.0 v1.0.1811.0 6/30/2020 6:59:57 PM 1.0.1811.0 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'. String @@ -381,7 +381,7 @@ Windows Terminal v1.0.1811.0 v1.0.1811.0 6/30/2020 6:59:57 PM 1.0.1811.0 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'. String @@ -419,9 +419,9 @@ Windows Terminal v1.0.1811.0 v1.0.1811.0 6/30/2020 6:59:57 PM 1.0.1811.0 -------------------------- EXAMPLE 1 -------------------------- - 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. @@ -438,11 +438,11 @@ Windows Terminal v1.0.1811.0 v1.0.1811.0 6/30/2020 6:59:57 PM 1.0.1811.0Get WTProcess - Get Windows Terminal processes + Get Windows Terminal processes. - 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. @@ -515,7 +515,7 @@ Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName Get WTReleaseNote - Get the latest Windows Terminal release information from GitHub + Get the latest Windows Terminal release information from GitHub. @@ -546,6 +546,17 @@ Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName False + + Preview + + Get the latest preview release. + + + SwitchParameter + + + False + @@ -573,6 +584,18 @@ Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName False + + Preview + + Get the latest preview release. + + SwitchParameter + + SwitchParameter + + + False + @@ -633,9 +656,9 @@ Notes : ## Changes -------------------------- Example 2 -------------------------- - 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. @@ -651,6 +674,10 @@ Notes : ## Changes Online Version: https://bit.ly/2Ck0MF6 + + Install-WTRelease + + @@ -659,7 +686,7 @@ Notes : ## Changes Install WTRelease - Install the latest Windows Terminal release + Install the latest Windows Terminal release. @@ -792,7 +819,7 @@ Notes : ## Changes Open WTDefault - Open Windows Terminal default.json file + Open Windows Terminal default.json file. @@ -851,11 +878,11 @@ Notes : ## Changes Test WTVersion - Test if newer version of Windows Terminal is installed. + Test if an updated version of Windows Terminal is installed. - 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. @@ -904,7 +931,7 @@ False Start-Process https://github.com/microsoft/terminal/releases } - 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. diff --git a/functions/Get-WTKeybindings.ps1 b/functions/Get-WTKeybindings.ps1 index 0b80eeb..883e4e5 100644 --- a/functions/Get-WTKeybindings.ps1 +++ b/functions/Get-WTKeybindings.ps1 @@ -13,7 +13,17 @@ Function Get-WTKeyBinding { $list = [System.Collections.Generic.List[Object]]::new() Write-Verbose "[$((Get-Date).TimeofDay)] Getting WindowsTerminal Appx package" - $install =(Get-AppxPackage -name Microsoft.WindowsTerminal).InstallLocation + <# + Need to get the correct application depending on whether running release or preview + #> + if ((Get-WTProcess | Where-Object {$_.name -eq 'WindowsTerminal'}).path -match 'preview') { + $pkg = "Microsoft.WindowsTerminalPreview" + } + else { + $pkg = "Microsoft.WindowsTerminal" + } + $install = (Get-AppxPackage -name $pkg).InstallLocation + Write-Verbose "[$((Get-Date).TimeofDay)] Getting defaults.json file" $defaults = Join-Path -path $install -ChildPath defaults.json @@ -23,7 +33,11 @@ Function Get-WTKeyBinding { #get the keybindings and add a property that indicates where the setting came from. Write-Verbose "[$((Get-Date).TimeofDay)] Parsing default keybindings" - $keys = $defaultsettings.keybindings | + <# + It looks like the json schema might be changing so I need to allow for name variations. + 8/1/2020 jdh + #> + $keys = $defaultsettings | Select-Object -Expandproperty "*bindings" | parsesetting | Select-Object -Property *, @{Name = "Source"; Expression = {"Defaults"}} @@ -31,29 +45,32 @@ Function Get-WTKeyBinding { #add the keybinding objects to the list $list.AddRange($keys) - Write-Verbose "[$((Get-Date).TimeofDay)] Getting user settings" - $settingsjson = "$ENV:Userprofile\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" - if (Test-Path $settingsjson) { - $settings = Get-Content -path $settingsjson | Where-Object {$_ -notmatch "//"} | ConvertFrom-Json + $settingsjson = $global:wtsettingspath + Write-Verbose "[$((Get-Date).TimeofDay)] Getting user settings from $settingsjson" + if (Test-Path -path $settingsjson) { + Write-Verbose "[$((Get-Date).TimeofDay)] Converting content to json" + $settings = Get-Content -path $settingsjson | Where-Object {$_ -notmatch "//"} | ConvertFrom-Json + #this might change and be bindings or keybindings #only process if there are keybindings - if ($settings.keybindings) { - $user = $settings.keybindings | - parsesetting | - Select-Object -Property *, @{Name = "Source"; Expression = {"Settings"}} - Write-Verbose "[$((Get-Date).TimeofDay)] Found $($keys.count) user keybindings" + $bind = $settings | Select-Object -ExpandProperty "*bindings" + if ($bind) { + $user =$bind | + parsesetting | + Select-Object -Property *, @{Name = "Source"; Expression = {"Settings"}} + Write-Verbose "[$((Get-Date).TimeofDay)] Found $($keys.count) user keybindings" - #if there is a duplicate key binding, remove the default - foreach ($item in $user) { - $existing = $list.where( {$_.keys -eq $item.keys}) - if ($existing) { + #if there is a duplicate key binding, remove the default + foreach ($item in $user) { + $existing = $list.where( {$_.keys -eq $item.keys}) + if ($existing) { Write-Verbose "[$((Get-Date).TimeofDay)] Detected an override of $($existing| Out-String)" - [void]($list.Remove($existing)) + [void]($list.Remove($existing)) + } + #add the entry + $list.Add($item) } - #add the entry - $list.Add($item) - } - } #if keybindings + } #if keybindings } Write-Verbose "[$((Get-Date).TimeofDay)] Formatting keybinding settings as $Format" diff --git a/functions/Get-WTProcess.ps1 b/functions/Get-WTProcess.ps1 index f2765cd..0793893 100644 --- a/functions/Get-WTProcess.ps1 +++ b/functions/Get-WTProcess.ps1 @@ -9,20 +9,25 @@ Function Get-WTProcess { Write-Verbose "[$((Get-Date).TimeofDay)] Getting parent process ID for process $pid" $wt = Get-CimInstance -ClassName Win32_process -filter "ProcessID=$pid" - if ($wt) { + #validate the parent process is Windows Terminal + $parent = Get-Process -id $wt.parentProcessID + Write-Verbose "[$((Get-Date).TimeofDay)] Found parent process $($parent.processname)" + if ($parent.processname -match "WindowsTerminal") { + Write-Verbose "[$((Get-Date).TimeofDay)] Getting child processes of ID $($wt.parentProcessID)" $procs = Get-CimInstance -classname Win32_Process -filter "ParentProcessID = $($wt.ParentProcessId)" -Property ProcessID | - ForEach-Object -Begin { Get-Process -id $wt.ParentProcessId} -process {Get-Process -id $_.processID} + ForEach-Object -Begin { Get-Process -id $wt.ParentProcessId} -process {Get-Process -id $_.processID} Write-Verbose "[$((Get-Date).TimeofDay)] Found $($procs.count) processes" #insert a custom type name to be used with a custom formatting file - $procs | ForEach-Object {$_.psobject.typenames.insert(0,"WTProcess")} + $procs | ForEach-Object {$_.psobject.typenames.insert(0, "WTProcess")} #write the results to the pipeline sorted by the start time $procs | Sort-Object -property StartTime } else { Write-Warning "This instance of PowerShell doesn't appear to be running in Windows Terminal." } - Write-Verbose "[$((Get-Date).TimeofDay)] Ending $($MyInvocation.MyCommand)" + + Write-Verbose "[$((Get-Date).TimeofDay)] Ending $($MyInvocation.MyCommand)" } diff --git a/functions/Get-WTReleaseNote.ps1 b/functions/Get-WTReleaseNote.ps1 index df8e919..ef2ece8 100644 --- a/functions/Get-WTReleaseNote.ps1 +++ b/functions/Get-WTReleaseNote.ps1 @@ -6,7 +6,9 @@ Function Get-WTReleaseNote { [Parameter(HelpMessage = "Create a markdown document")] [alias("md")] [switch]$AsMarkdown, - [switch]$Online + [switch]$Online, + [Parameter(HelpMessage = "Get the latest preview release")] + [switch]$Preview ) Write-Verbose "[$((Get-Date).TimeofDay)] Starting $($myinvocation.mycommand)" @@ -17,8 +19,15 @@ Function Get-WTReleaseNote { Write-Verbose "[$((Get-Date).TimeofDay)] Getting information from $uri" $get = Invoke-Restmethod -uri $uri -Method Get -ErrorAction stop - Write-Verbose "[$((Get-Date).TimeofDay)] Getting release information" - $data = $get | Where-Object {$_.prerelease -ne "true"} | Select-Object -first 1 + if ($Preview) { + Write-Verbose "[$((Get-Date).TimeofDay)] Getting PREVIEW release information" + $prerelease = "true" + } + else { + Write-Verbose "[$((Get-Date).TimeofDay)] Getting STABLE release information" + $prerelease = "false" + } + $data = $get | Where-Object {$_.prerelease -eq $prerelease} | Select-Object -first 1 $data | Select-Object -Property Name,tag_name,published_at,prerelease, diff --git a/functions/open-wtdefaults.ps1 b/functions/open-wtdefaults.ps1 index 34e4baf..0a27f16 100644 --- a/functions/open-wtdefaults.ps1 +++ b/functions/open-wtdefaults.ps1 @@ -1,26 +1,33 @@ -# a simple script to open the defaults.json file for Windows Terminal using -# the assoociate application for json files + Function Open-WTDefault { [CmdletBinding()] Param() Write-Verbose "[$((Get-Date).TimeofDay)] Starting $($MyInvocation.MyCommand)" - Write-Verbose "[$((Get-Date).TimeofDay)] Getting AppxPackage for Microsoft.WindowsTerminal" - $app = Get-AppxPackage Microsoft.WindowsTerminal - if (Test-Path $app.InstallLocation) { - $json = Join-Path -path $app.installlocation -ChildPath defaults.json + <# + Need to account for preview and/or stable releases. + Only run this command is a Windows Terminal session. + #> + + Write-Verbose "[$((Get-Date).TimeofDay)] Getting process path" + $wtProcess = Get-WTProcess | where-object {$_.name -eq 'WindowsTerminal'} + $appPath = Split-Path -path $wtProcess.path + + if ($appPath) { + Write-Verbose "[$((Get-Date).TimeofDay)] Using process path $appPath" + $json = Join-Path -path $appPath -ChildPath defaults.json + Write-Verbose "[$((Get-Date).TimeofDay)] Testing for $json" if (Test-Path $json) { Write-Verbose "[$((Get-Date).TimeofDay)] Opening $json" Invoke-Item $json } else { - Write-Warning "Could not find default.json file." + Write-Warning "Could not find $json." } } else { - Throw "Windows Terminal is not installed." + Throw "Windows Terminal is not installed or you are not running this session of PowerShell in it." } - Write-Verbose "[$((Get-Date).TimeofDay)] Ending $($MyInvocation.MyCommand)" } \ No newline at end of file diff --git a/tests/WTToolBox.Tests.ps1 b/tests/WTToolBox.Tests.ps1 index f91d9d1..75a04ea 100644 --- a/tests/WTToolBox.Tests.ps1 +++ b/tests/WTToolBox.Tests.ps1 @@ -106,7 +106,6 @@ InModuleScope WTToolBox { Context Input { - } #context input Context Output { @@ -166,7 +165,8 @@ InModuleScope WTToolBox { } } #context input Context Output { - + $global:wtSettingsPath = "Testdrive:\settings.json" + Mock Get-WTProcess {} mock parsesetting { @{ Action = "closeWindow" @@ -192,7 +192,7 @@ InModuleScope WTToolBox { return $fake } -ParameterFilter {$Path -eq "Testdrive:\defaults.json" } - Mock Get-Content { } -ParameterFilter {$Path -eq "$ENV:Userprofile\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"} + Mock Get-Content { } -ParameterFilter {$Path -eq "Testdrive:\settings.json"} Mock Get-Appxpackage { @{InstallLocation = "TestDrive:"} } -ParameterFilter {$Name -eq 'Microsoft.WindowsTerminal'} @@ -200,8 +200,9 @@ return $fake Mock Join-Path { "Testdrive:\defaults.json" } -ParameterFilter {$Path -eq "Testdrive:" -AND $childpath -eq "defaults.json" } + Mock Test-Path {$True} - $f = Get-WTKeybinding + $f = Get-WTKeybinding It "Should call Get-AppxPackage" { Assert-MockCalled "Get-AppxPackage" -Scope Context } @@ -296,10 +297,13 @@ return $fake } It "Should write a warning if not running in Windows Terminal" { - Mock Get-CimInstance {} -ParameterFilter {$Classname -eq "Win32_Process" -AND $filter -eq "ProcessID=$PID"} + + Mock Get-Process { + [pscustomobject]@{ProcessName="Foo"} + } -ParameterFilter {$ID -eq 123} Get-WTProcess -WarningAction SilentlyContinue -WarningVariable w - $w | Should be "This instance of PowerShell doesn't appear to be running in Windows Terminal." + $w | Should match "\w+" } } #context output @@ -323,19 +327,23 @@ return $fake Context Output { + Mock Get-WTProcess {} It "Should throw an exception if Windows Terminal is not installed" { - Mock Get-AppxPackage {} {Open-WTDefault} | Should Throw } It "Should write a warning if default.json is missing" { - Mock Get-AppxPackage { - @{InstallLocation = "Testdrive:\"} + Mock Get-WTProcess { + [pscustomobject]@{Name="WindowsTerminal";Path = "TestDrive:\windowsTerminal"} } - Mock Test-Path {$False} -ParameterFilter {$Path -eq "Testdrive:\" -AND $ChildPath -eq 'defaults.json'} + + Mock Test-Path {$False} Open-WTDefault -WarningAction SilentlyContinue -WarningVariable w - $w | Should be "Could not find default.json file." + $w | Should match "\w+" } It "Should open the file with Invoke-Item" { + Mock Get-WTProcess { + [pscustomobject]@{Name = "WindowsTerminal"; Path = "TestDrive:\windowsTerminal"} + } Mock Test-Path {$True} Mock Invoke-Item {} {Open-WTDefault} | Should not Throw