├── assets ├── readme.txt ├── wt-icon.png ├── wt-ps7.png ├── wtcurrent.png ├── wtprocess.png ├── wtsettings.png ├── get-wtprofile.png ├── wtkeybindings.png ├── wt-transparent.png ├── wtprocess-ansi.png ├── wttoolbox-icon.png ├── export-wtprofile.png ├── get-wtcolorscheme.png ├── get-wtkeybinding.png ├── import-wtprofile.png ├── compare-color-scheme.png ├── get-wtprofile-hidden.png ├── set-wtdefaultprofile.png └── get-wtprofile-properties.png ├── formats ├── readme.txt ├── wtprofile.format.ps1xml ├── wtcolorscheme.format.ps1xml ├── wtKeybinding.format.ps1xml └── wtprocess.format.ps1xml ├── .github └── ISSUE_TEMPLATE │ ├── config.yml │ ├── other-request.yml │ ├── feature-request.yml │ └── bug-report.yml ├── docs ├── Test-IsWTPreview.md ├── Open-WTDefault.md ├── Get-WTCurrent.md ├── Test-WTVersion.md ├── Get-WTCurrentRelease.md ├── Get-WTProcess.md ├── Set-WTDefaultProfile.md ├── Install-WTRelease.md ├── Import-WTProfile.md ├── Get-WTKeyBinding.md ├── Backup-WTSetting.md ├── Get-WTReleaseNote.md ├── Export-WTProfile.md ├── Get-WTColorScheme.md ├── Get-WTProfile.md ├── New-WTProfile.md └── about_WTToolbox.md ├── license.txt ├── functions ├── open-wtdefaults.ps1 ├── Get-WTCurrentRelease.ps1 ├── Get-WTCurrent.ps1 ├── Get-WTColorSchema.ps1 ├── Get-WTProfile.ps1 ├── Export-WTProfile.ps1 ├── Get-WTProcess.ps1 ├── Set-WTDefault.ps1 ├── Install-WTRelease.ps1 ├── Import-WTProfile.ps1 ├── Test-WTVersion.ps1 ├── Get-WTReleaseNote.ps1 ├── Backup-WTSettings.ps1 ├── private.ps1 ├── Get-WTKeybindings.ps1 └── New-WTProfile.ps1 ├── WTToolBox.psd1 ├── WTToolBox.psm1 ├── changelog.md ├── en-us └── about_WTToolbox.help.txt ├── README.md └── tests └── WTToolBox.Tests.ps1 /assets/readme.txt: -------------------------------------------------------------------------------- 1 | Image files and other assets mostly used for GitHub. -------------------------------------------------------------------------------- /formats/readme.txt: -------------------------------------------------------------------------------- 1 | These are the formatting files for custom objects in this module. -------------------------------------------------------------------------------- /assets/wt-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/wt-icon.png -------------------------------------------------------------------------------- /assets/wt-ps7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/wt-ps7.png -------------------------------------------------------------------------------- /assets/wtcurrent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/wtcurrent.png -------------------------------------------------------------------------------- /assets/wtprocess.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/wtprocess.png -------------------------------------------------------------------------------- /assets/wtsettings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/wtsettings.png -------------------------------------------------------------------------------- /assets/get-wtprofile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/get-wtprofile.png -------------------------------------------------------------------------------- /assets/wtkeybindings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/wtkeybindings.png -------------------------------------------------------------------------------- /assets/wt-transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/wt-transparent.png -------------------------------------------------------------------------------- /assets/wtprocess-ansi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/wtprocess-ansi.png -------------------------------------------------------------------------------- /assets/wttoolbox-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/wttoolbox-icon.png -------------------------------------------------------------------------------- /assets/export-wtprofile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/export-wtprofile.png -------------------------------------------------------------------------------- /assets/get-wtcolorscheme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/get-wtcolorscheme.png -------------------------------------------------------------------------------- /assets/get-wtkeybinding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/get-wtkeybinding.png -------------------------------------------------------------------------------- /assets/import-wtprofile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/import-wtprofile.png -------------------------------------------------------------------------------- /assets/compare-color-scheme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/compare-color-scheme.png -------------------------------------------------------------------------------- /assets/get-wtprofile-hidden.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/get-wtprofile-hidden.png -------------------------------------------------------------------------------- /assets/set-wtdefaultprofile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/set-wtdefaultprofile.png -------------------------------------------------------------------------------- /assets/get-wtprofile-properties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/HEAD/assets/get-wtprofile-properties.png -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: README 4 | url: https://github.com/jdhitsolutions/WTToolBox/blob/master/README.md 5 | about: Open this module's README.md file. 6 | -------------------------------------------------------------------------------- /docs/Test-IsWTPreview.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Test-IsWTPreview 9 | 10 | ## SYNOPSIS 11 | 12 | Test if running in Windows Terminal Preview 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Test-IsWTPreview [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | This simple command will test if you are running in Windows Terminal Preview. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Test-IsWTPreview 30 | False 31 | ``` 32 | 33 | ## PARAMETERS 34 | 35 | ### CommonParameters 36 | 37 | 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). 38 | 39 | ## INPUTS 40 | 41 | ### None 42 | 43 | ## OUTPUTS 44 | 45 | ### System.Boolean 46 | 47 | ## NOTES 48 | 49 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 50 | 51 | ## RELATED LINKS 52 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/other-request.yml: -------------------------------------------------------------------------------- 1 | name: 🤔Other Request or Question 2 | description: Open a request for all other issues 3 | title: "[Question]: " 4 | labels: ["question","triage"] 5 | assignees: 6 | - jdhitsolutions 7 | body: 8 | - type: textarea 9 | id: description 10 | attributes: 11 | label: Describe the question or issue 12 | description: What is on your mind? 13 | validations: 14 | required: true 15 | - type: dropdown 16 | id: psversion 17 | attributes: 18 | label: PowerShell version 19 | description: What version of PowerShell are you running? 20 | options: 21 | - '4.0' 22 | - '5.1' 23 | - 6.x 24 | - '7.0' 25 | - '7.1' 26 | - '7.2' 27 | - Other 28 | validations: 29 | required: false 30 | - type: dropdown 31 | id: platform 32 | attributes: 33 | label: Platform 34 | description: What operating system are you running? 35 | options: 36 | - Windows 10 Home 37 | - Windows 11 Home 38 | - Windows 10 Pro or Enterprise 39 | - Windows 11 Pro or Enterprise 40 | - MacOS 41 | - Linux 42 | - Other 43 | 44 | 45 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-2022 JDH Information Technology Solutions, Inc. 4 | 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /functions/open-wtdefaults.ps1: -------------------------------------------------------------------------------- 1 | 2 | Function Open-WTDefault { 3 | [CmdletBinding()] 4 | Param() 5 | 6 | Write-Verbose "[$((Get-Date).TimeofDay)] Starting $($MyInvocation.MyCommand)" 7 | 8 | <# 9 | Need to account for preview and/or stable releases. 10 | Only run this command is a Windows Terminal session. 11 | #> 12 | 13 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting process path" 14 | $wtProcess = Get-WTProcess | where-object {$_.name -eq 'WindowsTerminal'} 15 | $appPath = Split-Path -path $wtProcess.path 16 | 17 | if ($appPath) { 18 | Write-Verbose "[$((Get-Date).TimeofDay)] Using process path $appPath" 19 | $json = Join-Path -path $appPath -ChildPath defaults.json 20 | Write-Verbose "[$((Get-Date).TimeofDay)] Testing for $json" 21 | if (Test-Path $json) { 22 | Write-Verbose "[$((Get-Date).TimeofDay)] Opening $json" 23 | Invoke-Item $json 24 | } 25 | else { 26 | Write-Warning "Could not find $json." 27 | } 28 | } 29 | else { 30 | Throw "Windows Terminal is not installed or you are not running this session of PowerShell in it." 31 | } 32 | Write-Verbose "[$((Get-Date).TimeofDay)] Ending $($MyInvocation.MyCommand)" 33 | } -------------------------------------------------------------------------------- /docs/Open-WTDefault.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: https://bit.ly/2ZcqNPE 5 | schema: 2.0.0 6 | --- 7 | 8 | # Open-WTDefault 9 | 10 | ## SYNOPSIS 11 | 12 | Open Windows Terminal default.json file. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Open-WTDefault [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Windows Terminal uses a default.json file for default settings that can be overwritten with your settings.json file. This command will open the defaults.json file using the application associated with json files. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Open-WTDefault 30 | ``` 31 | 32 | ## PARAMETERS 33 | 34 | ### CommonParameters 35 | 36 | 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). 37 | 38 | ## INPUTS 39 | 40 | ### None 41 | 42 | ## OUTPUTS 43 | 44 | ### None 45 | 46 | ## NOTES 47 | 48 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 49 | 50 | ## RELATED LINKS 51 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.yml: -------------------------------------------------------------------------------- 1 | name: 💡Feature Request 2 | description: Request a new feature or enhancement 3 | title: "[Request]: " 4 | labels: ["enhancement","triage"] 5 | assignees: 6 | - jdhitsolutions 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: "## Thank you for bringing this to our attention." 11 | - type: textarea 12 | id: description 13 | attributes: 14 | label: Describe the request 15 | description: Please describe your feature request or enhancement in detail. What deficiency does it address in the module? What use cases support your request? 16 | validations: 17 | required: true 18 | - type: dropdown 19 | id: psversion 20 | attributes: 21 | label: PowerShell version 22 | description: What version of PowerShell are you running? 23 | options: 24 | - '4.0' 25 | - '5.1' 26 | - 6.x 27 | - '7.0' 28 | - '7.1' 29 | - '7.2' 30 | - Other 31 | validations: 32 | required: false 33 | - type: dropdown 34 | id: platform 35 | attributes: 36 | label: Platform 37 | description: What operating system are you running? 38 | options: 39 | - Windows 10 Home 40 | - Windows 11 Home 41 | - Windows 10 Pro or Enterprise 42 | - Windows 11 Pro or Enterprise 43 | - MacOS 44 | - Linux 45 | - Other 46 | 47 | 48 | -------------------------------------------------------------------------------- /functions/Get-WTCurrentRelease.ps1: -------------------------------------------------------------------------------- 1 | 2 | Function Get-WTCurrentRelease { 3 | [cmdletbinding()] 4 | [OutputType("PSCustomObject")] 5 | Param( 6 | [Parameter(HelpMessage = "Get the latest preview release")] 7 | [switch]$Preview 8 | ) 9 | 10 | Begin { 11 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.Mycommand)" 12 | $uri = "https://api.github.com/repos/microsoft/terminal/releases" 13 | } #begin 14 | Process { 15 | $get = Invoke-RestMethod -uri $uri -Method Get -ErrorAction stop 16 | if ($Preview) { 17 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting latest preview release" 18 | $data = $get | Where-Object {$_.prerelease -eq "true"} | Select-Object -first 1 19 | $local = GetWTPackage -preview 20 | } 21 | else { 22 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting latest stable release" 23 | $data = $get | Where-Object {$_.prerelease -ne "true"} | Select-Object -first 1 24 | $local = GetWTPackage 25 | } 26 | 27 | if ($data.tag_name) { 28 | [pscustomobject]@{ 29 | Name = $data.name 30 | Version = $data.tag_name 31 | Released = $($data.published_at -as [datetime]) 32 | LocalVersion = $local.version 33 | } 34 | } 35 | } #process 36 | 37 | End { 38 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.Mycommand)" 39 | } #end 40 | } -------------------------------------------------------------------------------- /functions/Get-WTCurrent.ps1: -------------------------------------------------------------------------------- 1 | Function Get-WTCurrent { 2 | [cmdletbinding()] 3 | [alias('gwtc')] 4 | [OutputType("wtProfile")] 5 | Param () 6 | Begin { 7 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" 8 | } #begin 9 | 10 | Process { 11 | if ($env:WT_PROFILE_ID) { 12 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting current profile settings for $($env:WT_PROFILE_ID)" 13 | 14 | #refresh the settings object to get current values 15 | $wtsettings.refresh() 16 | 17 | #Test if user is using the newer List entry in the json file 18 | #or is using a settings file based on defaults.json 19 | if ($wtsettings.profiles.list.guid) { 20 | $wtProfile = $wtsettings.profiles.list.where({ $_.guid -eq $env:WT_PROFILE_ID }) 21 | } 22 | elseif ($wtsettings.profiles.guid) { 23 | $wtProfile = $wtsettings.profiles.where( { $_.guid -eq $env:WT_PROFILE_ID }) 24 | } 25 | if ($wtProfile) { 26 | NewWTProfile $wtProfile 27 | } 28 | else { 29 | Write-Warning "Failed to find a profile with a GUID matching $env:WT_PROFILE_ID" 30 | } 31 | } 32 | Else { 33 | Write-Warning "This session does not appear to be running under Windows Terminal" 34 | } 35 | 36 | } #process 37 | 38 | End { 39 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" 40 | } #end 41 | 42 | } #close Get-WTCurrent -------------------------------------------------------------------------------- /functions/Get-WTColorSchema.ps1: -------------------------------------------------------------------------------- 1 | 2 | 3 | Function Get-WTColorScheme { 4 | [cmdletbinding()] 5 | [OutputType("wtColorScheme")] 6 | Param( 7 | [Parameter(Position = 0, HelpMessage = "Specify a Windows Terminal color scheme name. Wildcards are allowed. The default is all schemes.")] 8 | [ValidateNotNullOrEmpty()] 9 | [string]$Name = "*" 10 | ) 11 | Begin { 12 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" 13 | } #begin 14 | 15 | Process { 16 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting color scheme $Name" 17 | $schemes = $wtsettings.schemes | Where-Object { $_.name -like $Name } 18 | if ($schemes) { 19 | foreach ($scheme in $schemes) { 20 | $props = $scheme.psobject.properties.where({ $_.name -ne 'name' }) 21 | foreach ($item in $props) { 22 | $ansi = (Convert-HtmltoAnsi $item.value) 23 | [pscustomobject]@{ 24 | PSTypeName = "wtColorScheme" 25 | Property = $item.Name 26 | SchemeValue = $item.Value 27 | ANSIValue = $ansi 28 | Sample = "$([char]27)$ansi$($item.name)$([char]27)[0m" 29 | Name = $scheme.name 30 | } 31 | } #foreach item 32 | } #foreach scheme 33 | } #if 34 | else { 35 | Write-Warning "Could not find a matching color scheme." 36 | } 37 | } #process 38 | 39 | End { 40 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" 41 | 42 | } #end 43 | 44 | } #close Get-WTColorScheme -------------------------------------------------------------------------------- /docs/Get-WTCurrent.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: https://bit.ly/3ec5a6e 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-WTCurrent 9 | 10 | ## SYNOPSIS 11 | 12 | Get Windows Terminal profile settings for the current session. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Get-WTCurrent [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Use this command to display the Windows Terminal profile settings for the current PowerShell session. You cannot use this object to modify any settings. It is read-only. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Get-WTCurrent 30 | 31 | 32 | Name: Windows PowerShell No Profile [{ca3da2bd-de18-40f7-9fc6-234345d1e89f}] 33 | 34 | Title SourceCommand 35 | ----- ------------- 36 | PS No Profile powershell.exe -nologo -noexit -noprofile -file 37 | c:\scripts\miniprofile51.ps1 38 | ``` 39 | 40 | The output is custom object that may not reflect all of the defined setting. You can use use the $WTSettings variable to discover them with an expression like: 41 | 42 | $WTSettings.profiles.list | Where {$_.guid -eq $wtsettings.defaultProfile} 43 | 44 | 45 | ## PARAMETERS 46 | 47 | ### CommonParameters 48 | 49 | 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). 50 | 51 | ## INPUTS 52 | 53 | ### None 54 | 55 | ## OUTPUTS 56 | 57 | ### wtProfile 58 | 59 | ## NOTES 60 | 61 | This command has an alias of gwtc. 62 | 63 | Learn more about PowerShell: 64 | http://jdhitsolutions.com/blog/essential-powershell-resources/ 65 | 66 | ## RELATED LINKS 67 | 68 | [Get-WTProfile](Get-WTProfile.md) 69 | -------------------------------------------------------------------------------- /functions/Get-WTProfile.ps1: -------------------------------------------------------------------------------- 1 | Function Get-WTProfile { 2 | [cmdletbinding()] 3 | [outputType("wtProfile")] 4 | Param( 5 | [Parameter(Position = 0, HelpMessage = "Enter a Windows Terminal profile name. Wildcards are permitted.")] 6 | [ValidateNotNullOrEmpty()] 7 | [string]$Name = "*", 8 | [Parameter(HelpMessage = "Include hidden profiles.")] 9 | [switch]$Force 10 | ) 11 | Begin { 12 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" 13 | } #begin 14 | 15 | Process { 16 | if ($env:WT_PROFILE_ID) { 17 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting profile settings for $($env:WT_PROFILE_ID)" 18 | 19 | #refresh the settings object to get current values 20 | $wtsettings.refresh() 21 | $wtprofiles = $wtsettings.profiles.list 22 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Found a total of $($wtprofiles.count) profiles" 23 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting Windows Terminal profile $Name" 24 | $wtprofiles = $wtprofiles.where({$_.name -like "$Name"}) 25 | if (-Not $Force) { 26 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Filtering out hidden profiles" 27 | $wtProfiles = $wtprofiles.where({-Not $_.hidden}) 28 | } 29 | foreach ($wtProfile in $wtprofiles) { 30 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] $($wtprofile.name)" 31 | NewWTprofile $wtProfile 32 | } #foreach $wtProfile 33 | } 34 | else { 35 | Write-Warning "Failed to find a Windows Terminal profiles. Are you running this command in Windows Terminal" 36 | } 37 | 38 | } #process 39 | 40 | End { 41 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" 42 | } #end 43 | 44 | } #close Get-WTProfile 45 | -------------------------------------------------------------------------------- /WTToolBox.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module WTToolBox 3 | # 4 | 5 | @{ 6 | 7 | RootModule = 'WTToolBox.psm1' 8 | ModuleVersion = '1.15.0' 9 | CompatiblePSEditions = @('Desktop', 'Core') 10 | GUID = 'd7249a30-1995-47f7-9882-f3b6f246a14b' 11 | Author = 'Jeff Hicks' 12 | CompanyName = 'JDH Information Technology Solutions, Inc.' 13 | Copyright = '(c) 2020-2022 Jeff Hicks. All rights reserved.' 14 | Description = 'A set of PowerShell functions for managing and working with the Windows Terminal application from Microsoft.' 15 | PowerShellVersion = '5.1' 16 | #PowerShellHostName = 'ConsoleHost' 17 | # TypesToProcess = @() 18 | FormatsToProcess = @( 19 | "formats\wtprocess.format.ps1xml", 20 | "formats\wtKeybinding.format.ps1xml", 21 | "formats\wtprofile.format.ps1xml", 22 | "formats\wtcolorscheme.format.ps1xml" 23 | ) 24 | FunctionsToExport = 'Backup-WTSetting', 'Get-WTKeyBinding', 'Get-WTProcess', 25 | 'Open-WTDefault', 'Test-WTVersion', 'Get-WTReleaseNote', 'Get-WTCurrent', 26 | 'Get-WTCurrentRelease', 'Install-WTRelease', 'Test-IsWTPreview', 27 | 'Get-WTProfile', 'Set-WTDefaultProfile', 'Get-WTColorScheme', 28 | 'New-WTProfile', 'Export-WTProfile', 'Import-WTProfile' 29 | #VariablesToExport = '' 30 | aliasesToExport = 'Install-WindowsTerminal', 'gwtp', 'gwtc', 'gwtk', 'bwt' 31 | PrivateData = @{ 32 | 33 | PSData = @{ 34 | Tags = @('WindowsTerminal', 'wt', 'terminal') 35 | LicenseUri = 'https://github.com/jdhitsolutions/WTToolbox/blob/master/license.txt' 36 | ProjectUri = 'https://github.com/jdhitsolutions/WTToolbox' 37 | IconUri = 'https://raw.githubusercontent.com/jdhitsolutions/WTToolbox/master/assets/wt-transparent.png' 38 | } # End of PSData hashtable 39 | 40 | } # End of PrivateData hashtable 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /functions/Export-WTProfile.ps1: -------------------------------------------------------------------------------- 1 | 2 | 3 | Function Export-WTProfile { 4 | [cmdletbinding(SupportsShouldProcess)] 5 | Param( 6 | [Parameter( 7 | Position = 0, 8 | HelpMessage = "Specify a profile name. Wildards are permitted." 9 | )] 10 | [ValidateNotNullorEmpty()] 11 | [string]$Name = "*", 12 | [Parameter(HelpMessage = "Specify the json filepath.")] 13 | [ValidateNotNullOrEmpty()] 14 | [ValidateScript({ 15 | if (Split-Path $_ -parent | Test-Path) { 16 | If ($_ -match "\.json$") { 17 | $True 18 | } 19 | else { 20 | Throw "$_ does not appear to be a json file." 21 | $False 22 | } 23 | } 24 | else { 25 | Throw "Can't verify the location in $_." 26 | $false 27 | } 28 | })] 29 | [string]$Path = "$($env:computername)-wtprofile.json", 30 | 31 | [Parameter(HelpMessage = "Write the json file to the pipeline")] 32 | [switch]$Passthru 33 | ) 34 | Begin { 35 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" 36 | $wtsettings.refresh() 37 | } #begin 38 | 39 | Process { 40 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Exporting Windows Terminal profile(s) to $Path" 41 | $profiles = ($wtsettings.profiles.list).where({$_.name -like $Name -AND $_.commandline}) 42 | if ($profiles) { 43 | $profiles | ForEach-Object { 44 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] $($_.name)" 45 | } 46 | $profiles | ConvertTo-Json | Out-File -FilePath $path 47 | if ($Passthru) { 48 | Get-Item -Path $path 49 | } 50 | } 51 | else { 52 | Write-Warning "No matching Windows Terminal profiles found." 53 | } 54 | } #process 55 | 56 | End { 57 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" 58 | } #end 59 | 60 | } #close Export-WTProfile -------------------------------------------------------------------------------- /docs/Test-WTVersion.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: https://bit.ly/38Fh1s5 5 | schema: 2.0.0 6 | --- 7 | 8 | # Test-WTVersion 9 | 10 | ## SYNOPSIS 11 | 12 | Test if an updated version of Windows Terminal is installed. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Test-WTVersion [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | 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. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | 30 | PS C:\> Test-WTVersion 31 | False 32 | ``` 33 | 34 | Windows Terminal has not changed since the last check. 35 | 36 | ### Example 2 37 | 38 | ```powershell 39 | PS C:\> if ( $env:wt_session -AND Test-WTVersion) { 40 | Write-Host "A newer version of Windows Terminal is now installed." -foreground Yellow 41 | Start-Process https://github.com/microsoft/terminal/releases 42 | } 43 | ``` 44 | 45 | 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. 46 | 47 | ## PARAMETERS 48 | 49 | ### CommonParameters 50 | 51 | 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). 52 | 53 | ## INPUTS 54 | 55 | ### None 56 | 57 | ## OUTPUTS 58 | 59 | ### System.Boolean 60 | 61 | ## NOTES 62 | 63 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 64 | 65 | ## RELATED LINKS 66 | 67 | [Get-WTCurrentRelease](Get-WTCurrentRelease) 68 | -------------------------------------------------------------------------------- /docs/Get-WTCurrentRelease.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: https://bit.ly/2AKSPby 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-WTCurrentRelease 9 | 10 | ## SYNOPSIS 11 | 12 | Get the current Windows Terminal release. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Get-WTCurrentRelease [-Preview] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | 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. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Get-WTCurrentRelease 30 | 31 | Name Version Released LocalVersion 32 | ---- ------- -------- ------------ 33 | Windows Terminal v1.3.2651.0 v1.3.2651.0 9/22/2020 4:00:29 PM 1.2.2381.0 34 | ``` 35 | 36 | ### Example 2 37 | 38 | ```powershell 39 | PS C:\> Get-WTCurrentRelease -Preview 40 | 41 | Name Version Released LocalVersion 42 | ---- ------- -------- ------------ 43 | Windows Terminal Preview v1.4.2652.0 v1.4.2652.0 9/22/2020 4:00:31 PM 1.3.2382.0 44 | ``` 45 | 46 | ## PARAMETERS 47 | 48 | ### -Preview 49 | 50 | Get the latest preview release. 51 | 52 | ```yaml 53 | Type: SwitchParameter 54 | Parameter Sets: (All) 55 | Aliases: 56 | 57 | Required: False 58 | Position: Named 59 | Default value: None 60 | Accept pipeline input: False 61 | Accept wildcard characters: False 62 | ``` 63 | 64 | ### CommonParameters 65 | 66 | 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). 67 | 68 | ## INPUTS 69 | 70 | ### None 71 | 72 | ## OUTPUTS 73 | 74 | ### PSCustomObject 75 | 76 | ## NOTES 77 | 78 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 79 | 80 | ## RELATED LINKS 81 | 82 | [Test-WTVersion](Test-WTVersion.md) 83 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.yml: -------------------------------------------------------------------------------- 1 | name: 🪲 Bug Report 2 | description: Report a bug or problem. 3 | title: "[Bug]: " 4 | labels: ["bug","triage"] 5 | assignees: 6 | - jdhitsolutions 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: "## Thank you for bringing this to our attention." 11 | - type: textarea 12 | id: description 13 | attributes: 14 | label: Describe the problem 15 | description: Please describe the bug or problem including the exact syntax you are using and any error or warning messages. 16 | validations: 17 | required: true 18 | - type: textarea 19 | id: expected-behavior 20 | attributes: 21 | label: Expectation 22 | description: What did you expect to happen? 23 | - type: textarea 24 | id: additional-info 25 | attributes: 26 | label: Additional Information 27 | description: Do you have any additional information or context that you think will be helpful in resolving this issue? 28 | - type: dropdown 29 | id: psversion 30 | attributes: 31 | label: PowerShell version 32 | description: What version of PowerShell are you running? 33 | options: 34 | - '4.0' 35 | - '5.1' 36 | - 6.x 37 | - '7.0' 38 | - '7.1' 39 | - '7.2' 40 | - Other 41 | validations: 42 | required: true 43 | - type: dropdown 44 | id: platform 45 | attributes: 46 | label: Platform 47 | description: What operating system are you running? 48 | options: 49 | - Windows 10 Home 50 | - Windows 11 Home 51 | - Windows 10 Pro or Enterprise 52 | - Windows 11 Pro or Enterprise 53 | - MacOS 54 | - Linux 55 | - Other 56 | - type: checkboxes 57 | id: checks 58 | attributes: 59 | label: Additional Checks 60 | description: Have you verified the following? 61 | options: 62 | - label: You are using the latest version of this module. 63 | required: true 64 | - label: You have read this repository's README file. 65 | - label: You have read full help and examples for the command you are having problems with. 66 | - label: You are running PowerShell in an elevated session. 67 | - label: You are running in a traditional PowerShell console or Windows Terminal 68 | 69 | -------------------------------------------------------------------------------- /functions/Get-WTProcess.ps1: -------------------------------------------------------------------------------- 1 | 2 | #get the Windows Terminal process and its children 3 | Function Get-WTProcess { 4 | [cmdletbinding()] 5 | [alias("gwtp")] 6 | [OutputType("WTProcess")] 7 | Param() 8 | 9 | Write-Verbose "[$((Get-Date).TimeofDay)] Starting $($MyInvocation.MyCommand)" 10 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting parent process ID for process $pid" 11 | $wt = Get-CimInstance -ClassName Win32_process -Filter "ProcessID=$pid" 12 | #validate the parent process is Windows Terminal 13 | $parent = Get-Process -Id $wt.parentProcessID 14 | if ($parent.processname -match "WindowsTerminal" ) { 15 | Write-Verbose "[$((Get-Date).TimeofDay)] Found parent process $($parent.processname) [$($parent.iD)]" 16 | #use existing $wt variable 17 | $Verified = $True 18 | } 19 | elseif ($parent.parent.processname -match "WindowsTerminal") { 20 | Write-Verbose "[$((Get-Date).TimeofDay)] Found parent-parent process $($parent.parent.processname) [$($parent.id)]" 21 | #if parent process is cmd, assume you are running PowerShell 7.x Preview 22 | if ($parent.ProcessName -eq 'cmd') { 23 | $PSPreview = $True 24 | } 25 | $parent = $parent.parent 26 | $Verified = $True 27 | } 28 | else { 29 | Write-Warning "This instance of PowerShell doesn't appear to be running in Windows Terminal." 30 | } 31 | 32 | If ($Verified) { 33 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting child processes of ID $($parent.ID)" 34 | 35 | $procs = Get-CimInstance -ClassName Win32_Process -Filter "ParentProcessID = $($Parent.Id)" -Property ProcessID | 36 | ForEach-Object -Begin { Get-Process -Id $Parent.Id } -Process { Get-Process -Id $_.processID } -end { 37 | if ($PSPreview) { 38 | Get-Process -id $pid 39 | } 40 | } 41 | 42 | Write-Verbose "[$((Get-Date).TimeofDay)] Found $($procs.count) processes" 43 | 44 | #insert a custom type name to be used with a custom formatting file 45 | $procs | ForEach-Object { $_.psobject.typenames.insert(0, "WTProcess") } 46 | #write the results to the pipeline sorted by the start time 47 | $procs | Sort-Object -Property StartTime 48 | } #if verified 49 | 50 | Write-Verbose "[$((Get-Date).TimeofDay)] Ending $($MyInvocation.MyCommand)" 51 | } 52 | -------------------------------------------------------------------------------- /docs/Get-WTProcess.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: https://bit.ly/38JZf7d 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-WTProcess 9 | 10 | ## SYNOPSIS 11 | 12 | Get Windows Terminal processes. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Get-WTProcess [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | 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 your PowerShell process in green text. Note that if you are running nested processes, that is PowerShell running PowerShell, you may get incomplete or incorrect results. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Get-WTProcess 30 | 31 | Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName 32 | ------- ------ ----- ----- ------ -- -- ----------- 33 | 913 48 110304 95016 458.05 7112 1 WindowsTerminal 34 | 150 10 2264 7092 0.80 8600 1 OpenConsole 35 | 2387 149 373980 351940 40.28 32548 1 pwsh 36 | 150 11 2300 7272 54.94 9080 1 OpenConsole 37 | 1912 106 517584 300388 124.61 3680 1 powershell 38 | 150 10 2208 7748 0.13 14292 1 OpenConsole 39 | 743 50 176648 124820 7.64 29668 1 powershell 40 | 144 10 2228 8888 0.14 14132 1 OpenConsole 41 | 67 5 4128 3632 0.02 31992 1 cmd 42 | 148 11 2236 8900 0.16 26764 1 OpenConsole 43 | 116 7 1248 5620 0.03 15308 1 wsl 44 | ``` 45 | 46 | The current PowerShell process will be formatted in color. 47 | 48 | ## PARAMETERS 49 | 50 | ### CommonParameters 51 | 52 | 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). 53 | 54 | ## INPUTS 55 | 56 | ### None 57 | 58 | ## OUTPUTS 59 | 60 | ### WTProcess 61 | 62 | ## NOTES 63 | 64 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 65 | 66 | ## RELATED LINKS 67 | 68 | [Get-Process]() 69 | -------------------------------------------------------------------------------- /docs/Set-WTDefaultProfile.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-WTDefaultProfile 9 | 10 | ## SYNOPSIS 11 | 12 | Set the default Windows Terminal profile 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Set-WTDefaultProfile [-Guid] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | This command will set the default Windows Terminal profile. It will update your settings.json file. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Get-WTProfile -name Powershell | Set-WTDefaultProfile 30 | ``` 31 | 32 | Set the default profile. The easiest approach is to use Get-WTProfile to select the profile you wish to use and pipe that to Set-WTDefaultProfile.md. 33 | 34 | ## PARAMETERS 35 | 36 | ### -Confirm 37 | 38 | Prompts you for confirmation before running the cmdlet. 39 | 40 | ```yaml 41 | Type: SwitchParameter 42 | Parameter Sets: (All) 43 | Aliases: cf 44 | 45 | Required: False 46 | Position: Named 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -Guid 53 | 54 | The Windows Terminal profile guid including the {}. The easiest approach is to use Get-WTProfile to select the profile you wish to use and pipe that to Set-WTDefaultProfile.md. 55 | 56 | ```yaml 57 | Type: String 58 | Parameter Sets: (All) 59 | Aliases: 60 | 61 | Required: True 62 | Position: 0 63 | Default value: None 64 | Accept pipeline input: True (ByPropertyName) 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### -WhatIf 69 | Shows what would happen if the cmdlet runs. 70 | The cmdlet is not run. 71 | 72 | ```yaml 73 | Type: SwitchParameter 74 | Parameter Sets: (All) 75 | Aliases: wi 76 | 77 | Required: False 78 | Position: Named 79 | Default value: None 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ### CommonParameters 85 | 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). 86 | 87 | ## INPUTS 88 | 89 | ### System.String 90 | 91 | ## OUTPUTS 92 | 93 | ### none 94 | 95 | ## NOTES 96 | 97 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 98 | 99 | ## RELATED LINKS 100 | 101 | [Get-WTProfile](Get-WTProfile.md) 102 | -------------------------------------------------------------------------------- /docs/Install-WTRelease.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: https://bit.ly/2O5k0kh 5 | schema: 2.0.0 6 | --- 7 | 8 | # Install-WTRelease 9 | 10 | ## SYNOPSIS 11 | 12 | Install the latest Windows Terminal release. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Install-WTRelease [-Preview] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Normally, you can install Windows Terminal from the Microsoft Store. Or you can use this command to download and install the package from GitHub. Use this command when you want to install the latest preview. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Install-WTRelease 30 | ``` 31 | 32 | Install the latest Windows Terminal release. Add -Preview if you want the preview release. 33 | 34 | ## PARAMETERS 35 | 36 | ### -Confirm 37 | 38 | Prompts you for confirmation before running the cmdlet. 39 | 40 | ```yaml 41 | Type: SwitchParameter 42 | Parameter Sets: (All) 43 | Aliases: cf 44 | 45 | Required: False 46 | Position: Named 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -Preview 53 | 54 | Install the latest preview release package from Github. 55 | 56 | ```yaml 57 | Type: SwitchParameter 58 | Parameter Sets: (All) 59 | Aliases: 60 | 61 | Required: False 62 | Position: Named 63 | Default value: None 64 | Accept pipeline input: True (ByValue) 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### -WhatIf 69 | 70 | Shows what would happen if the cmdlet runs. 71 | The cmdlet is not run. 72 | 73 | ```yaml 74 | Type: SwitchParameter 75 | Parameter Sets: (All) 76 | Aliases: wi 77 | 78 | Required: False 79 | Position: Named 80 | Default value: None 81 | Accept pipeline input: False 82 | Accept wildcard characters: False 83 | ``` 84 | 85 | ### CommonParameters 86 | 87 | 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). 88 | 89 | ## INPUTS 90 | 91 | ### System.Management.Automation.SwitchParameter 92 | 93 | ## OUTPUTS 94 | 95 | ### none 96 | 97 | ## NOTES 98 | 99 | This command has an alias of Install-WindowsTerminal. 100 | 101 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 102 | 103 | ## RELATED LINKS 104 | 105 | [Get-WTCurrentRelease](Get-WTCurrentRelease.md) 106 | -------------------------------------------------------------------------------- /formats/wtprofile.format.ps1xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | 13 | default 14 | 15 | wtProfile 16 | 17 | 18 | 26 | 27 | $text = "{0} [{1}]" -f $_.Name,$_.GUID 28 | 29 | if ($host.name -match "console" -AND $_.Hidden) { 30 | "$([char]27)[31m$text$([char]27)[0m" 31 | } 32 | elseif ($host.name -match "console" -AND $_.IsDefault) { 33 | 34 | "$([char]27)[92m$text$([char]27)[0m" 35 | } 36 | else { 37 | $text 38 | } 39 | 40 | 41 | 42 | 43 | 45 | 46 | 47 | 48 | 30 49 | left 50 | 51 | 52 | 53 | left 54 | 55 | 56 | 57 | 58 | 59 | 60 | 64 | 65 | Title 66 | 67 | 68 | SourceCommand 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /formats/wtcolorscheme.format.ps1xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | 13 | default 14 | 15 | wtColorScheme 16 | 17 | 18 | 26 | Name 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 14 36 | left 37 | 38 | 39 | 40 | 14 41 | left 42 | 43 | 44 | 45 | 18 46 | left 47 | 48 | 49 | 50 | 33 51 | left 52 | 53 | 54 | 55 | 56 | 57 | 61 | 62 | Property 63 | 64 | 65 | 66 | SchemeValue 67 | 68 | 69 | ANSIValue 70 | 71 | 72 | Sample 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /functions/Set-WTDefault.ps1: -------------------------------------------------------------------------------- 1 | Function Set-WTDefaultProfile { 2 | [cmdletbinding(SupportsShouldProcess)] 3 | Param( 4 | [Parameter( 5 | Position = 0, 6 | Mandatory, 7 | ValueFromPipelineByPropertyName, 8 | HelpMessage = "The Windows Terminal profile guid including the {}." 9 | )] 10 | [ValidateNotNullOrEmpty()] 11 | [ValidateScript({ 12 | Try { 13 | [void]([guid]::Parse($_)) 14 | $True 15 | } 16 | Catch { 17 | Throw "The value cannot be parsed as a guid." 18 | $false 19 | } 20 | })] 21 | [string]$Guid 22 | ) 23 | Begin { 24 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" 25 | #get all defined GUIDs 26 | #I'll assume $wtsettings is current 27 | #$wtsettings.refresh() 28 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Building a profile guid list" 29 | $list = $WTSettings.profiles.list | Select-Object -property name,guid | 30 | Group-Object -property GUID -ashashtable -asString 31 | } #begin 32 | 33 | Process { 34 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Using guid $Guid" 35 | if ($list.keys -contains $Guid) { 36 | #define a regex to get the defaultprofile from the settings.json file 37 | $rx=[System.Text.RegularExpressions.Regex]::new("(?<=defaultProfile"":\s"")$($wtsettings.DefaultProfile)","MultiLine") 38 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Using regex $($rx.toString())" 39 | #initialize a collection to hold the settings json file 40 | $file = [System.Collections.Generic.list[string]]::new() 41 | #get the content 42 | $settingsContent = Get-Content $WTSettingsPath 43 | #add the content to the collection 44 | $settingsContent | foreach-Object { $file.add($_)} 45 | $name = $list.$guid.name 46 | $i = $file.FindIndex({$args[0] -match $rx}) 47 | $line = $file[$i] 48 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Replacing-> $($line.trim())" 49 | $file[$i] = $rx.replace($line,$guid) 50 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] .....with-> $($file[$i].trim())" 51 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Updating $WTSettingsPath" 52 | if ($PSCmdlet.ShouldProcess("$name $guid", "Set default Windows Terminal profile")) { 53 | $file | Out-File -FilePath $WTSettingsPath 54 | } #whatif 55 | } 56 | else { 57 | Write-Warning "Can't find a Windows Terminal profile with a guid of $Guid." 58 | } 59 | } #process 60 | 61 | End { 62 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" 63 | } #end 64 | 65 | } #close Set-WTDefault -------------------------------------------------------------------------------- /functions/Install-WTRelease.ps1: -------------------------------------------------------------------------------- 1 | Function Install-WTRelease { 2 | [cmdletbinding(SupportsShouldProcess)] 3 | [OutputType("none")] 4 | [Alias("Install-WindowsTerminal")] 5 | Param( 6 | [Parameter(ValueFromPipeline)] 7 | [switch]$Preview 8 | ) 9 | Begin { 10 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" 11 | 12 | $uri = "https://api.github.com/repos/microsoft/terminal/releases" 13 | 14 | } #begin 15 | 16 | Process { 17 | Try { 18 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting information from $uri" 19 | $get = Invoke-RestMethod -Uri $uri -Method Get -ErrorAction stop 20 | 21 | if ($Preview) { 22 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting latest preview release" 23 | $data = $get | Where-Object { $_.prerelease -eq "true" } | Select-Object -First 1 24 | } 25 | else { 26 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting latest stable release" 27 | $data = $get | Where-Object { $_.prerelease -ne "true" } | Select-Object -First 1 28 | } 29 | #download 30 | #Need to filter out the preinstallkie.zip (Issue #7) 31 | $msix = ($data.assets).where( { $_.name -match '\.msixbundle$' }) 32 | #($data.assets.name).where({$_ -match '\.msixbundle$'}) 33 | 34 | #Need to acocunt for Windows 10 or Windows 11 bundle - JDH 5/25/2022 35 | if ($msix.count -gt 1) { 36 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Found $($msix.count) possible packages" 37 | $os = (Get-CimInstance win32_operatingsystem).caption 38 | #Convert value like Windows 11 to Win_11 to match msix name 39 | $short = [system.text.RegularExpressions.Regex]::Match($os, "Windows\s+\d{2}").value -replace "Windows\s+", "Win" 40 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting matching package for $short" 41 | $msix = $msix | Where-Object { $_.name -match $short } 42 | } 43 | if ($msix.name.count -eq 1) { 44 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Downloading $($msix.name)" 45 | $src = $msix.browser_download_url 46 | $target = Join-Path -Path $env:temp -ChildPath $msix.name.trim() 47 | if ($pscmdlet.shouldProcess($src, "Download and install")) { 48 | Invoke-WebRequest -Uri $src -OutFile $target -DisableKeepAlive -UseBasicParsing -ErrorAction Stop 49 | Add-AppxPackage -Path $target -ErrorAction stop 50 | } 51 | } 52 | else { 53 | Write-Warning "Failed to find a single matching msix package to install for this operating system." 54 | } 55 | } 56 | Catch { 57 | Throw $_ 58 | } 59 | 60 | } #process 61 | 62 | End { 63 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" 64 | 65 | } #end 66 | 67 | } #close Install-WTRelease -------------------------------------------------------------------------------- /docs/Import-WTProfile.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Import-WTProfile 9 | 10 | ## SYNOPSIS 11 | 12 | Import a Windows Terminal profile. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Import-WTProfile [-Path] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | If you exported Windows Terminal profiles to a Json file, you can use Import-WTProfile to add them to your settings file. You might do this when setting up a new desktop or restoring a backup. The imported profiles must have unique names. It is assumed the guids are unique and will not conflict with existing profile guids. All imported profiles will go to the top of your profile list. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Import-WTProfile c:\work\saved.json -Verbose 30 | VERBOSE: [12:46:33.2526304 BEGIN ] Starting Import-WTProfile 31 | VERBOSE: [12:46:33.2588630 PROCESS] Importing Windows Terminal profiles from c:\work\saved.json 32 | VERBOSE: [12:46:33.2603038 PROCESS] Found 3 profiles 33 | VERBOSE: [12:46:33.2607900 PROCESS] Importing PS7.2 No Profile 34 | WARNING: There is already a profile with the name of Windows PowerShell No Profile. Skipping import. 35 | VERBOSE: [12:46:33.2612329 PROCESS] Importing WinCmd 36 | VERBOSE: [12:46:33.2622307 END ] Update settings.json 37 | VERBOSE: [12:46:33.2763273 END ] Ending Import-WTProfile 38 | ``` 39 | 40 | Import profiles from a Json file created with Export-WTProfile. 41 | 42 | ## PARAMETERS 43 | 44 | ### -Confirm 45 | 46 | Prompts you for confirmation before running the cmdlet. 47 | 48 | ```yaml 49 | Type: SwitchParameter 50 | Parameter Sets: (All) 51 | Aliases: cf 52 | 53 | Required: False 54 | Position: Named 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -Path 61 | 62 | Specify the path to a json file created with Export-WTProfile. 63 | 64 | ```yaml 65 | Type: String 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: True 70 | Position: 0 71 | Default value: None 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -WhatIf 77 | 78 | Shows what would happen if the cmdlet runs. 79 | The cmdlet is not run. 80 | 81 | ```yaml 82 | Type: SwitchParameter 83 | Parameter Sets: (All) 84 | Aliases: wi 85 | 86 | Required: False 87 | Position: Named 88 | Default value: None 89 | Accept pipeline input: False 90 | Accept wildcard characters: False 91 | ``` 92 | 93 | ### CommonParameters 94 | 95 | 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). 96 | 97 | ## INPUTS 98 | 99 | ### None 100 | 101 | ## OUTPUTS 102 | 103 | ### None 104 | 105 | ## NOTES 106 | 107 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 108 | 109 | ## RELATED LINKS 110 | 111 | [Export-WTProfile](Export-WTProfile.md) 112 | -------------------------------------------------------------------------------- /docs/Get-WTKeyBinding.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: https://bit.ly/2Zcqg06 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-WTKeyBinding 9 | 10 | ## SYNOPSIS 11 | 12 | Display Windows Terminal key binding information. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Get-WTKeyBinding [-Action ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Get Windows Terminal key binding settings. If a keybinding from your settings.json file has the same key combination as a default, the default setting is overwritten. Use the Action parameter to filter for specific types of actions. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | PS C:\Get-WTKeyBinding 30 | ``` 31 | 32 | Get Windows Terminal key bindings and display in the default formatted table view. 33 | 34 | ### EXAMPLE 2 35 | 36 | ```powershell 37 | PS C:\> Get-WTKeyBinding -Action *font* | Format-List 38 | 39 | 40 | Source: Defaults 41 | 42 | 43 | Action : adjustFontSize 44 | ActionSettings : delta = 1 45 | Keys : ctrl+= 46 | 47 | Action : adjustFontSize 48 | ActionSettings : delta = -1 49 | Keys : ctrl+- 50 | 51 | Action : resetFontSize 52 | ActionSettings : 53 | Keys : ctrl+0 54 | ``` 55 | 56 | Display a specific action. Wildcards are permitted. 57 | 58 | ### EXAMPLE 3 59 | 60 | ```powershell 61 | PS C:\> Get-WTKeyBinding | where keys | sort keys | Format-Table -view keys 62 | 63 | Keys ActionSettings Action Source 64 | ---- -------------- ------ ------ 65 | alt+down direction = down moveFocus Defaults 66 | alt+enter toggleFullscreen Defaults 67 | alt+f4 closeWindow Defaults 68 | alt+left direction = left moveFocus Defaults 69 | alt+right direction = right moveFocus Defaults 70 | alt+shift+- split = horizontal splitPane Defaults 71 | ... 72 | ``` 73 | 74 | Get all key bindings where a key combination has been assigned and display the results the Keys table view. 75 | 76 | ## PARAMETERS 77 | 78 | ### -Action 79 | 80 | Select an action type. The command should autocomplete possible choices. 81 | 82 | ```yaml 83 | Type: String 84 | Parameter Sets: (All) 85 | Aliases: 86 | 87 | Required: False 88 | Position: Named 89 | Default value: None 90 | Accept pipeline input: False 91 | Accept wildcard characters: True 92 | ``` 93 | 94 | ### CommonParameters 95 | 96 | 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). 97 | 98 | ## INPUTS 99 | 100 | ## OUTPUTS 101 | 102 | ### wtKeybinding 103 | 104 | ## NOTES 105 | 106 | This command has an alias of gwtk. 107 | 108 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 109 | 110 | ## RELATED LINKS 111 | -------------------------------------------------------------------------------- /docs/Backup-WTSetting.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: https://bit.ly/3e874EH 5 | schema: 2.0.0 6 | --- 7 | 8 | # Backup-WTSetting 9 | 10 | ## SYNOPSIS 11 | 12 | Backup Windows Terminal settings.json file. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Backup-WTSetting [[-Limit] ] [-Destination] [-Passthru] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | 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. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Backup-WTSetting -destination D:\OneDrive\Backups 30 | ``` 31 | 32 | Create backups to D:\OneDrive\Backups using the default limit. 33 | 34 | ## PARAMETERS 35 | 36 | ### -Confirm 37 | 38 | Prompts you for confirmation before running the cmdlet. 39 | 40 | ```yaml 41 | Type: SwitchParameter 42 | Parameter Sets: (All) 43 | Aliases: cf 44 | 45 | Required: False 46 | Position: Named 47 | Default value: False 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -Destination 53 | 54 | Specify the backup location. It must exist. 55 | 56 | ```yaml 57 | Type: String 58 | Parameter Sets: (All) 59 | Aliases: 60 | 61 | Required: True 62 | Position: 1 63 | Default value: None 64 | Accept pipeline input: False 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### -Limit 69 | 70 | The number of backup files to keep. 71 | 72 | ```yaml 73 | Type: Int32 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 0 79 | Default value: 7 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ### -WhatIf 85 | 86 | Shows what would happen if the cmdlet runs. 87 | The cmdlet is not run. 88 | 89 | ```yaml 90 | Type: SwitchParameter 91 | Parameter Sets: (All) 92 | Aliases: wi 93 | 94 | Required: False 95 | Position: Named 96 | Default value: False 97 | Accept pipeline input: False 98 | Accept wildcard characters: False 99 | ``` 100 | 101 | ### -Passthru 102 | 103 | Write backup file objects to the pipeline. Otherwise the command doesn't write anything to the pipeline. 104 | 105 | ```yaml 106 | Type: SwitchParameter 107 | Parameter Sets: (All) 108 | Aliases: 109 | 110 | Required: False 111 | Position: Named 112 | Default value: None 113 | Accept pipeline input: False 114 | Accept wildcard characters: False 115 | ``` 116 | 117 | ### CommonParameters 118 | 119 | 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). 120 | 121 | ## INPUTS 122 | 123 | ### None 124 | 125 | ## OUTPUTS 126 | 127 | ### None 128 | 129 | ### System.IO.FileInfo 130 | 131 | ## NOTES 132 | 133 | This command has an alias of bwt. 134 | 135 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 136 | 137 | ## RELATED LINKS 138 | -------------------------------------------------------------------------------- /functions/Import-WTProfile.ps1: -------------------------------------------------------------------------------- 1 | Function Import-WTProfile { 2 | [cmdletbinding(SupportsShouldProcess)] 3 | [outputtype("none")] 4 | Param( 5 | [Parameter( 6 | Position = 0, 7 | Mandatory, 8 | HelpMessage = "Specify the path to a json file created with Export-WTProfile." 9 | )] 10 | [ValidateScript({ 11 | #validate file exits 12 | if (Test-Path $_) { 13 | #now test for extension 14 | if ($_ -match "\.json$") { 15 | $True 16 | } 17 | else { 18 | Throw "The filename must end in '.json'." 19 | } 20 | } 21 | else { 22 | Throw "Cannot find file $_." 23 | } 24 | })] 25 | [string]$Path 26 | ) 27 | Begin { 28 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" 29 | #get existing names 30 | $current = $wtsettings.profiles.list.name 31 | #get current settings in a list 32 | $list = [System.Collections.Generic.list[string]]::new() 33 | Get-Content $wtsettingspath | ForEach-Object { 34 | $list.add($_) 35 | } 36 | #this list will hold the new profiles 37 | $add = [System.Collections.Generic.list[string]]::new() 38 | } #begin 39 | 40 | Process { 41 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Importing Windows Terminal profiles from $path" 42 | Try { 43 | #convert to objects for validation. Objects that pass validation will 44 | #be converted back to json 45 | $import = Get-Content -Path $Path | ConvertFrom-Json -ErrorAction stop 46 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Found $($import.count) profiles" 47 | } 48 | Catch { 49 | Throw $_ 50 | #make sure to bail out of the command 51 | return 52 | } 53 | 54 | foreach ($item in $import) { 55 | if ($current -contains $item.Name) { 56 | Write-Warning "There is already a profile with the name of $($item.name). Skipping import." 57 | } 58 | else { 59 | [string[]]$new = $item | ConvertTo-Json 60 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Importing $($item.name)" 61 | $add.AddRange($new) 62 | #append a comma 63 | $add[-1] += "," 64 | } 65 | } #foreach 66 | 67 | } #process 68 | 69 | End { 70 | if ($add.count -gt 0) { 71 | $i = $list.FindIndex({ $args[0] -match '"list":' }) 72 | #now find the opening [ 73 | While ($list[$i] -notmatch "\[") { 74 | $i++ 75 | } 76 | #insert the new profile(s) here 77 | $list.InsertRange($i + 1, $add) 78 | #update the settings file 79 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Update settings.json" 80 | $list | Out-File -FilePath $WTsettingsPath 81 | } 82 | else { 83 | Write-Warning "Nothing found to import." 84 | } 85 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" 86 | } #end 87 | 88 | } #close New-WTProfile -------------------------------------------------------------------------------- /functions/Test-WTVersion.ps1: -------------------------------------------------------------------------------- 1 | 2 | Function Test-WTVersion { 3 | [CmdletBinding()] 4 | [OutputType([boolean])] 5 | Param() 6 | 7 | Write-Verbose "[$((Get-Date).TimeofDay)] Starting $($myinvocation.MyCommand)" 8 | Write-Verbose "[$((Get-Date).TimeofDay)] Get the currently installed application" 9 | #only check if not running the Preview build 10 | if (Test-IsWTPreview) { 11 | Write-Host "You are running the Windows Terminal Preview" -ForegroundColor Yellow 12 | $pkg = GetWTPackage -preview 13 | } 14 | else { 15 | $pkg = GetWTPackage 16 | } 17 | 18 | If ($pkg) { 19 | $pkg | Out-String | Write-Verbose 20 | #get the version number 21 | [version]$current = $pkg.Version 22 | Write-Verbose "[$((Get-Date).TimeofDay)] Found version $current" 23 | #check for previous version file 24 | $verFile = Join-Path -path $home -ChildPath wtver.json 25 | Write-Verbose "[$((Get-Date).TimeofDay)] Testing for version tracking file $verFile" 26 | 27 | if (Test-Path -path $verfile) { 28 | Write-Verbose "[$((Get-Date).TimeofDay)] Comparing versions" 29 | $in = Get-Content -Path $verFile | ConvertFrom-Json 30 | $previous = $in.VersionString -as [version] 31 | 32 | Write-Verbose "[$((Get-Date).TimeofDay)] Comparing stored version $previous with current version $current" 33 | If ($current -gt $previous) { 34 | Write-Verbose "[$((Get-Date).TimeofDay)] A newer version of Windows Terminal has been detected." 35 | $True 36 | } 37 | else { 38 | Write-Verbose "[$((Get-Date).TimeofDay)] Windows Terminal is up to date." 39 | $False 40 | } 41 | } 42 | 43 | #create the json file, adding the version as a string which makes it easier to reconstruct 44 | Write-Verbose "[$((Get-Date).TimeofDay)] Writing current information to $verFile." 45 | $current | Select-Object *, 46 | @{Name = "VersionString"; Expression = {$_.tostring()}}, 47 | @{Name = "Date"; Expression = {(Get-Date).DateTime}} | 48 | ConvertTo-Json | Out-File -FilePath $verfile -Encoding ascii -Force 49 | } # if package found 50 | else { 51 | Throw "Windows Terminal is not installed." 52 | } 53 | Write-Verbose "[$((Get-Date).TimeofDay)] Ending $($myinvocation.MyCommand)" 54 | } #close function 55 | 56 | Function Test-IsWTPreview { 57 | [cmdletbinding()] 58 | [outputtype([Boolean])] 59 | Param() 60 | 61 | Write-Verbose "[$((Get-Date).TimeofDay)] Starting $($myinvocation.MyCommand)" 62 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting process id $pid" 63 | #get current process 64 | $current = Get-CimInstance win32_process -Filter "processid=$pid" 65 | 66 | #get WindowsTerminal parent 67 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting parent process id $($current.parentprocessid)" 68 | $parent = Get-CimInstance win32_process -Filter "processid=$($current.parentprocessid)" 69 | 70 | #test if path matches the preview executable 71 | Write-Verbose "[$((Get-Date).TimeofDay)] Testing path $($parent.ExecutablePath)" 72 | $parent.ExecutablePath -match "WindowsTerminalPreview" 73 | 74 | Write-Verbose "[$((Get-Date).TimeofDay)] Ending $($myinvocation.MyCommand)" 75 | } 76 | -------------------------------------------------------------------------------- /functions/Get-WTReleaseNote.ps1: -------------------------------------------------------------------------------- 1 | Function Get-WTReleaseNote { 2 | [CmdletBinding()] 3 | [outputtype([System.String])] 4 | [outputtype("WTReleaseNote")] 5 | Param( 6 | [Parameter(HelpMessage = "Create a markdown document")] 7 | [alias("md")] 8 | [switch]$AsMarkdown, 9 | [switch]$Online, 10 | [Parameter(HelpMessage = "Get the latest preview release")] 11 | [switch]$Preview 12 | ) 13 | 14 | Write-Verbose "[$((Get-Date).TimeofDay)] Starting $($myinvocation.mycommand)" 15 | 16 | $uri = "https://api.github.com/repos/microsoft/terminal/releases" 17 | 18 | Try { 19 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting information from $uri" 20 | $get = Invoke-Restmethod -uri $uri -Method Get -ErrorAction stop 21 | $get | out-string | write-verbose 22 | if ($Preview) { 23 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting PREVIEW release information" 24 | $data = $get | Where-Object { $_.prerelease } | Select-Object -first 1 25 | } 26 | else { 27 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting STABLE release information" 28 | $data = $get | Where-Object { -Not $_.prerelease } | Select-Object -first 1 29 | } 30 | $data | out-string | write-verbose 31 | $data | Select-Object -Property Name,tag_name,published_at,prerelease, 32 | 33 | @{Name="bodyLength";Expression = {$_.body.length}} | Out-String | Write-Verbose 34 | 35 | if ($online) { 36 | Write-Verbose "[$((Get-Date).TimeofDay)] Opening $($data.html_url) in your web browser." 37 | Try { 38 | Start-Process $data.html_url -ErrorAction Stop 39 | } 40 | Catch { 41 | Throw $_ 42 | } 43 | } 44 | elseif ($AsMarkdown) { 45 | [regex]$rx = "(?<=\()#\d+(?=\))" 46 | Write-Verbose "[$((Get-Date).TimeofDay)] Adding links to issues in the body" 47 | $issues = $rx.Matches($data.body) 48 | foreach ($issue in $issues) { 49 | $issnum = $issue.value -replace "\D","" 50 | $replace = "[$($issue.value)](https://github.com/microsoft/terminal/issues/$issnum)" 51 | Write-Verbose "[$((Get-Date).TimeofDay)] ... $replace" 52 | $data.body = $data.body -replace $issue.value,$replace 53 | } 54 | 55 | Write-Verbose "[$((Get-Date).TimeofDay)] Creating a markdown document" 56 | $md = @" 57 | # $($data.name) 58 | 59 | > Version : $($data.tag_name) 60 | > 61 | > Published : $($data.published_at -as [datetime]) 62 | > 63 | > Pre-Release : $($data.prerelease) 64 | 65 | $($data.body.trim()) 66 | 67 | *** 68 | 69 | *Source: $($data.html_url)* 70 | "@ 71 | #write the object to the pipeline 72 | $md 73 | } #as markdown 74 | else { 75 | Write-Verbose "[$((Get-Date).TimeofDay)] Creating WTReleaseNote" 76 | 77 | [pscustomobject]@{ 78 | PSTypename = "WTReleaseNote" 79 | Name = $data.name 80 | Version = $data.tag_name 81 | Published = $($data.published_at -as [datetime]) 82 | Prerelease = If ($data.prerelease -eq 'true') {$True} else {$false} 83 | Notes = $data.body.trim() 84 | } 85 | } 86 | } #try 87 | Catch { 88 | Throw $_ 89 | } 90 | Write-Verbose "[$((Get-Date).TimeofDay)] Ending $($myinvocation.mycommand)" 91 | } #end function -------------------------------------------------------------------------------- /functions/Backup-WTSettings.ps1: -------------------------------------------------------------------------------- 1 | 2 | #create backup copies of the Windows Terminal settings.json file 3 | 4 | Function Backup-WTSetting { 5 | 6 | [CmdletBinding(SupportsShouldProcess)] 7 | [alias("bwt")] 8 | Param( 9 | #how many backup copies should be saved 10 | [ValidateScript({$_ -ge 1})] 11 | [int]$Limit = 7, 12 | #backup folder 13 | [parameter(Mandatory, HelpMessage = "Specify the backup location. It must already exist.")] 14 | [ValidateScript( {Test-Path $_})] 15 | [string]$Destination, 16 | [switch]$Passthru 17 | ) 18 | 19 | Write-Verbose "[$((Get-Date).TimeofDay)] Starting $($myinvocation.MyCommand)" 20 | #use the variable defined in the module 21 | $json = $global:WTSettingsPath 22 | #"$ENV:Userprofile\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" 23 | 24 | if (Test-Path $json) { 25 | 26 | Write-Verbose "[$((Get-Date).TimeofDay)] Backing up $json to $Destination" 27 | Write-Verbose "[$((Get-Date).TimeofDay)] Get existing backups from $Destination and saving as an array sorted by name" 28 | 29 | [array]$bak = Get-ChildItem -path $Destination\settings.bak*.json | Sort-Object -Property LastWriteTime 30 | 31 | if ($bak.count -eq 0) { 32 | Write-Verbose "[$((Get-Date).TimeofDay)] Creating first backup copy." 33 | [int]$new = 1 34 | } 35 | else { 36 | $bak | Out-String | Write-Verbose 37 | #get the numeric value 38 | [int]$counter = ([regex]"\d+").match($bak[-1]).value 39 | Write-Verbose "[$((Get-Date).TimeofDay)] Last backup is #$counter" 40 | 41 | [int]$new = $counter + 1 42 | Write-Verbose "[$((Get-Date).TimeofDay)] Creating backup copy $new" 43 | } 44 | 45 | $backup = Join-Path -path $Destination -ChildPath "settings.bak$new.json" 46 | Write-Verbose "[$((Get-Date).TimeofDay)] Creating backup $backup" 47 | Copy-Item -Path $json -Destination $backup 48 | 49 | #update the list of backups sorted by age and delete extras 50 | Write-Verbose "Removing any extra backup files over the limit of $Limit" 51 | 52 | Get-ChildItem -path $Destination\settings.bak*.json | 53 | Sort-Object -Property LastWriteTime -Descending | 54 | Select-Object -Skip $Limit | Remove-Item 55 | 56 | #renumber backup files 57 | Write-Verbose "[$((Get-Date).TimeofDay)] Renumbering backup files" 58 | <# 59 | You can't rename a file if it will conflict with an existing file so files will be copied 60 | to a temp folder with a new name, the old file deleted and then the copy restored 61 | #> 62 | Get-ChildItem -path $Destination\settings.bak*.json | 63 | Sort-Object -Property LastWriteTime | 64 | ForEach-Object -Begin {$n = 0} -process { 65 | #rename each file with a new number 66 | $n++ 67 | $temp = Join-Path -path $env:TEMP -ChildPath "settings.bak$n.json" 68 | 69 | Write-Verbose "[$((Get-Date).TimeofDay)] Copying temp file to $temp" 70 | $_ | Copy-Item -Destination $temp 71 | 72 | Write-Verbose "[$((Get-Date).TimeofDay)] Removing $($_.name)" 73 | $_ | Remove-Item 74 | 75 | } -end { 76 | Write-Verbose "[$((Get-Date).TimeofDay)] Restoring temp files to $Destination" 77 | Get-ChildItem -Path "$env:TEMP\settings.bak*.json" | Move-Item -Destination $Destination -PassThru:$passthru 78 | } 79 | 80 | } 81 | else { 82 | Write-Warning "Failed to find expected settings file $json" 83 | } 84 | Write-Verbose "[$((Get-Date).TimeofDay)] Ending $($myinvocation.MyCommand)" 85 | } -------------------------------------------------------------------------------- /docs/Get-WTReleaseNote.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: https://bit.ly/2Ck0MF6 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-WTReleaseNote 9 | 10 | ## SYNOPSIS 11 | 12 | Get the latest Windows Terminal release information from GitHub. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Get-WTReleaseNote [-AsMarkdown] [-Online] [-Preview] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | This command will query the Windows Terminal GitHub repository to get information about the latest release. You can also open the release notes directly on Github using the -Online parameter. This parameter will take precedence. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Get-WTReleaseNote 30 | 31 | 32 | Name : Windows Terminal v1.0.1401.0 33 | Version : v1.0.1401.0 34 | Published : 5/19/2020 4:08:09 PM 35 | Prerelease : False 36 | Notes : ## Changes 37 | 38 | * Windows Terminal now ships with [Cascadia Code 2005.15](https://github.com/microsoft/cascadia-code/releases/tag/v2005.15). 39 | * All emoji are now sized as recommended by Unicode 13.0. You _will_ see some emoji that are smaller than you want them to be. That's just a fact of life. (#5934) 40 | * Documentation for Windows Terminal has moved to [docs.microsoft.com](http://docs.microsoft.com/windows/terminal)! 41 | * Existing user documentation in this repository will be moving to a nice farm upstate in short order. 42 | 43 | It will not escape your notice that there are two packages in this release: 44 | * `WindowsTerminal` is the stable build of Terminal. 45 | * `WindowsTerminalPreview` is the preview version, which can be installed _side-by-side_ with the stable version. 46 | ``` 47 | 48 | ### Example 2 49 | 50 | ```powershell 51 | PS C:\> Get-WTReleaseNote -AsMarkdown -Preview | Show-Markdown | more 52 | ``` 53 | 54 | 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. 55 | 56 | ### Example 3 57 | 58 | ```powershell 59 | PS C:\> Get-WTReleaseNote -online 60 | ``` 61 | 62 | Open the release notes page from GitHub in your default web browser. 63 | 64 | ## PARAMETERS 65 | 66 | ### -AsMarkdown 67 | 68 | Create a markdown document. Referenced GitHub issues should have links to the original issue. 69 | 70 | ```yaml 71 | Type: SwitchParameter 72 | Parameter Sets: (All) 73 | Aliases: md 74 | 75 | Required: False 76 | Position: Named 77 | Default value: False 78 | Accept pipeline input: False 79 | Accept wildcard characters: False 80 | ``` 81 | 82 | ### -Online 83 | 84 | Open the online release notes. This parameter will take precedence. 85 | 86 | ```yaml 87 | Type: SwitchParameter 88 | Parameter Sets: (All) 89 | Aliases: 90 | 91 | Required: False 92 | Position: Named 93 | Default value: False 94 | Accept pipeline input: False 95 | Accept wildcard characters: False 96 | ``` 97 | 98 | ### -Preview 99 | 100 | Get the latest preview release. 101 | 102 | ```yaml 103 | Type: SwitchParameter 104 | Parameter Sets: (All) 105 | Aliases: 106 | 107 | Required: False 108 | Position: Named 109 | Default value: None 110 | Accept pipeline input: False 111 | Accept wildcard characters: False 112 | ``` 113 | 114 | ### CommonParameters 115 | 116 | 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). 117 | 118 | ## INPUTS 119 | 120 | ### None 121 | 122 | ## OUTPUTS 123 | 124 | ### System.String 125 | 126 | ### WTReleaseNote 127 | 128 | ## NOTES 129 | 130 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 131 | 132 | ## RELATED LINKS 133 | 134 | [Install-WTRelease](Install-WTRelease.md) 135 | -------------------------------------------------------------------------------- /docs/Export-WTProfile.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Export-WTProfile 9 | 10 | ## SYNOPSIS 11 | 12 | Export a Windows Terminal profile. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Export-WTProfile [[-Name] ] [-Path ] [-Passthru] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Export-WTProfile makes it easier to backup your custom Windows Terminal profiles. The export is to a Json file which you can import using Import-WTProfile. The export process will only export profiles with a commandline setting. It will ignore profiles like Azure Cloud Shell that use a source. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Export-WTProfile -Path c:\work\all-wt-profiles.json -Passthru -Verbose 30 | VERBOSE: [11:44:27.0121595 BEGIN ] Starting Export-WTProfile 31 | VERBOSE: Parsing C:\Users\Jeff\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json 32 | VERBOSE: Adding custom properties 33 | VERBOSE: Adding a method to refresh the object 34 | VERBOSE: Setting the WTSettings variable in the global scope 35 | VERBOSE: [11:44:27.0195423 PROCESS] Exporting Windows Terminal profile(s) to c:\work\all-wt-profiles.json 36 | VERBOSE: [11:44:27.0200009 PROCESS] PS7 No Profile 37 | VERBOSE: [11:44:27.0203622 PROCESS] Windows PowerShell 38 | VERBOSE: [11:44:27.0207093 PROCESS] Windows PowerShell No Profile 39 | VERBOSE: [11:44:27.0210646 PROCESS] Command Prompt 40 | VERBOSE: [11:44:27.0214242 PROCESS] DOM1 41 | VERBOSE: [11:44:27.0217793 PROCESS] Ubuntu 42 | 43 | Directory: C:\work 44 | 45 | 46 | Mode LastWriteTime Length Name 47 | ---- ------------- ------ ---- 48 | -a--- 1/7/2022 11:44 AM 3535 all-wt-profiles.json 49 | VERBOSE: [11:44:27.0274847 END ] Ending Export-WTProfile 50 | ``` 51 | 52 | Export all custom profiles to a json file. 53 | 54 | ## PARAMETERS 55 | 56 | ### -Confirm 57 | 58 | Prompts you for confirmation before running the cmdlet. 59 | 60 | ```yaml 61 | Type: SwitchParameter 62 | Parameter Sets: (All) 63 | Aliases: cf 64 | 65 | Required: False 66 | Position: Named 67 | Default value: None 68 | Accept pipeline input: False 69 | Accept wildcard characters: False 70 | ``` 71 | 72 | ### -Name 73 | 74 | Specify a profile name. Wildards are permitted. The named profile must have a commandline value. 75 | 76 | ```yaml 77 | Type: String 78 | Parameter Sets: (All) 79 | Aliases: 80 | 81 | Required: False 82 | Position: 0 83 | Default value: None 84 | Accept pipeline input: False 85 | Accept wildcard characters: True 86 | ``` 87 | 88 | ### -Passthru 89 | 90 | Write the json file to the pipeline 91 | 92 | ```yaml 93 | Type: SwitchParameter 94 | Parameter Sets: (All) 95 | Aliases: 96 | 97 | Required: False 98 | Position: Named 99 | Default value: None 100 | Accept pipeline input: False 101 | Accept wildcard characters: False 102 | ``` 103 | 104 | ### -Path 105 | 106 | Specify the json filepath. Default is a file in the current directory. 107 | 108 | ```yaml 109 | Type: String 110 | Parameter Sets: (All) 111 | Aliases: 112 | 113 | Required: False 114 | Position: Named 115 | Default value: $($env:computername)-wtprofile.json 116 | Accept pipeline input: False 117 | Accept wildcard characters: False 118 | ``` 119 | 120 | ### -WhatIf 121 | 122 | Shows what would happen if the cmdlet runs. 123 | The cmdlet is not run. 124 | 125 | ```yaml 126 | Type: SwitchParameter 127 | Parameter Sets: (All) 128 | Aliases: wi 129 | 130 | Required: False 131 | Position: Named 132 | Default value: None 133 | Accept pipeline input: False 134 | Accept wildcard characters: False 135 | ``` 136 | 137 | ### CommonParameters 138 | 139 | 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). 140 | 141 | ## INPUTS 142 | 143 | ### None 144 | 145 | ## OUTPUTS 146 | 147 | ### None 148 | 149 | ### System.IO.FileInfo 150 | 151 | ## NOTES 152 | 153 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 154 | 155 | ## RELATED LINKS 156 | 157 | [Import-WTProfile](Import-WTProfile.md) 158 | 159 | [Backup-WTSetting](Backup-WTSetting.md) 160 | -------------------------------------------------------------------------------- /docs/Get-WTColorScheme.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-WTColorScheme 9 | 10 | ## SYNOPSIS 11 | 12 | Get Windows Terminal color schemes 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Get-WTColorScheme [[-Name] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Get-WTColorScheme will enumerate the defined Windows Terminal color schemes. You can specify a scheme by name. The default is to return all schemes. The formatted output includes a color sample so you can view the results in your terminal session. For example, different schemes may have different definitions for "red". 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> PS C:\> Get-WTColorScheme 'One Half Dark' 30 | 31 | Name: One Half Dark 32 | 33 | Property SchemeValue ANSIValue Sample 34 | -------- ----------- --------- ------ 35 | background #282C34 [38;2;40;44;52m background 36 | black #282C34 [38;2;40;44;52m black 37 | blue #61AFEF [38;2;97;175;239m blue 38 | brightBlack #5A6374 [38;2;90;99;116m brightBlack 39 | brightBlue #61AFEF [38;2;97;175;239m brightBlue 40 | brightCyan #56B6C2 [38;2;86;182;194m brightCyan 41 | brightGreen #98C379 [38;2;152;195;121m brightGreen 42 | brightPurple #C678DD [38;2;198;120;221m brightPurple 43 | brightRed #E06C75 [38;2;224;108;117m brightRed 44 | brightWhite #FFFFFF [38;2;255;255;255m brightWhite 45 | brightYellow #E5C07B [38;2;229;192;123m brightYellow 46 | cursorColor #FFFFFF [38;2;255;255;255m cursorColor 47 | cyan #56B6C2 [38;2;86;182;194m cyan 48 | foreground #DCDFE4 [38;2;220;223;228m foreground 49 | green #98C379 [38;2;152;195;121m green 50 | purple #C678DD [38;2;198;120;221m purple 51 | red #E06C75 [38;2;224;108;117m red 52 | selectionBackground #FFFFFF [38;2;255;255;255m selectionBackground 53 | white #DCDFE4 [38;2;220;223;228m white 54 | yellow #E5C07B [38;2;229;192;123m yellow 55 | ``` 56 | 57 | The Sample property will be displayed using the ANSI escape sequence defined in ANSIValue. 58 | 59 | ### Example 2 60 | 61 | ```powershell 62 | PS C:\> Get-WTColorScheme *dark | where Property -match "red|green|yellow|white" 63 | 64 | Name: One Half Dark 65 | 66 | Property SchemeValue ANSIValue Sample 67 | -------- ----------- --------- ------ 68 | brightGreen #98C379 [38;2;152;195;121m brightGreen 69 | brightRed #E06C75 [38;2;224;108;117m brightRed 70 | brightWhite #FFFFFF [38;2;255;255;255m brightWhite 71 | brightYellow #E5C07B [38;2;229;192;123m brightYellow 72 | green #98C379 [38;2;152;195;121m green 73 | red #E06C75 [38;2;224;108;117m red 74 | white #DCDFE4 [38;2;220;223;228m white 75 | yellow #E5C07B [38;2;229;192;123m yellow 76 | 77 | Name: Solarized Dark 78 | 79 | Property SchemeValue ANSIValue Sample 80 | -------- ----------- --------- ------ 81 | brightGreen #586E75 [38;2;88;110;117m brightGreen 82 | brightRed #CB4B16 [38;2;203;75;22m brightRed 83 | brightWhite #FDF6E3 [38;2;253;246;227m brightWhite 84 | brightYellow #657B83 [38;2;101;123;131m brightYellow 85 | green #859900 [38;2;133;153;0m green 86 | red #DC322F [38;2;220;50;47m red 87 | white #EEE8D5 [38;2;238;232;213m white 88 | yellow #B58900 [38;2;181;137;0m yellow 89 | ``` 90 | 91 | Compare properties across different color schemes. 92 | 93 | ## PARAMETERS 94 | 95 | ### -Name 96 | 97 | Specify a Windows Terminal color scheme name. 98 | Wildcards are allowed. 99 | The default is all schemes. 100 | 101 | ```yaml 102 | Type: String 103 | Parameter Sets: (All) 104 | Aliases: 105 | 106 | Required: False 107 | Position: 0 108 | Default value: * 109 | Accept pipeline input: False 110 | Accept wildcard characters: True 111 | ``` 112 | 113 | ### CommonParameters 114 | 115 | 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 | 117 | ## INPUTS 118 | 119 | ### None 120 | 121 | ## OUTPUTS 122 | 123 | ### wtColorScheme 124 | 125 | ## NOTES 126 | 127 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 128 | 129 | ## RELATED LINKS 130 | -------------------------------------------------------------------------------- /docs/Get-WTProfile.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-WTProfile 9 | 10 | ## SYNOPSIS 11 | 12 | Get a Windows Terminal profile 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Get-WTProfile [[-Name] ] [-Force] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | You can use this command to discover settings for your Windows Terminal profiles. The default behavior is to show all non-hidden profiles. But you can filter by name using wildcards. Or use -Force to include hidden profiles. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Get-WPprofile 30 | 31 | 32 | Name: PowerShell [{574e775e-4f2a-5b96-ac1e-a2962a402336}] 33 | 34 | Title SourceCommand 35 | ----- ------------- 36 | Windows.Terminal.PowershellCore 37 | 38 | 39 | Name: PS7 No Profile [{c6783a98-47d9-4610-bc68-7a3f909e94fb}] 40 | 41 | Title SourceCommand 42 | ----- ------------- 43 | PS7 NoProfile C:\Program Files\PowerShell\7\pwsh.exe -noprofile 44 | ... 45 | ``` 46 | 47 | The default output is formatted as a table. The default profile will be highlighted in green, or whatever is defined for green in your color scheme. 48 | 49 | ### Example 2 50 | 51 | ```powershell 52 | PS C:\> Get-WTProfile -Force | Sort-Object Name 53 | 54 | 55 | Name: Azure Cloud Shell [{b453ae62-4e3d-5e58-b989-0a998ec441b8}] 56 | 57 | Title SourceCommand 58 | ----- ------------- 59 | Windows.Terminal.Azure 60 | 61 | 62 | Name: Command Prompt [{0caa0dad-35be-5f56-a8ff-afceeeaa6101}] 63 | 64 | Title SourceCommand 65 | ----- ------------- 66 | cmd.exe 67 | 68 | 69 | Name: DOM1 [{b89c512a-cd2b-4fb4-a6d2-3366cee85970}] 70 | 71 | Title SourceCommand 72 | ----- ------------- 73 | PSRemote: DOM1.Company.Pri powershell.exe -nologo -noprofile -noexit -file 74 | c:\scripts\wtpsremote.ps1 -computername dom1 75 | -credential company\artd -remoteprofile 76 | c:\scripts\dom1-remoteprofile.ps1 77 | ... 78 | ``` 79 | 80 | Hidden profiles will have their name and guid displayed in red. 81 | 82 | ### Example 3 83 | 84 | ```powershell 85 | PS C:\> Get-WTProfile ubuntu* | Select-Object * 86 | 87 | Name : Ubuntu 88 | Guid : {22010c0e-c464-49b2-97ef-fe764973cf54} 89 | Hidden : False 90 | Title : Ubuntu 91 | SourceCommand : wsl.exe -d Ubuntu-20.04 92 | Icon : C:\Users\Jeff\OneDrive\windowsterminal\ProfileIcons\ubuntu32x32.png 93 | StartingDirectory : %USERPROFILE% 94 | ColorScheme : One Half Dark 95 | UseAcrylic : 96 | AcrylicOpacity : 97 | ``` 98 | 99 | The Get-WTProfile command only displays a subset of properties. But you can use an expression like: 100 | 101 | $wtsettings.profiles.list | Where name -match ubuntu 102 | 103 | To view all properties. This expression uses the WTToolbox modules wtsettings variable. You need to import the module before you can use this variable. 104 | 105 | ## PARAMETERS 106 | 107 | ### -Force 108 | 109 | Include hidden profiles. 110 | 111 | ```yaml 112 | Type: SwitchParameter 113 | Parameter Sets: (All) 114 | Aliases: 115 | 116 | Required: False 117 | Position: Named 118 | Default value: None 119 | Accept pipeline input: False 120 | Accept wildcard characters: False 121 | ``` 122 | 123 | ### -Name 124 | 125 | Enter a Windows Terminal profile name. 126 | Wildcards are permitted. 127 | 128 | ```yaml 129 | Type: String 130 | Parameter Sets: (All) 131 | Aliases: 132 | 133 | Required: False 134 | Position: 0 135 | Default value: * 136 | Accept pipeline input: False 137 | Accept wildcard characters: True 138 | ``` 139 | 140 | ### CommonParameters 141 | 142 | 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). 143 | 144 | ## INPUTS 145 | 146 | ### None 147 | 148 | ## OUTPUTS 149 | 150 | ### wtProfile 151 | 152 | ## NOTES 153 | 154 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 155 | 156 | ## RELATED LINKS 157 | 158 | [Get-WTCurrent](Get-WTCurrent.md) 159 | 160 | [Set-WTDefaultProfile](Set-WTDefaultProfile.md) 161 | 162 | [New-WTProfile](New-WTProfile.md) 163 | -------------------------------------------------------------------------------- /WTToolBox.psm1: -------------------------------------------------------------------------------- 1 | 2 | #region main code 3 | 4 | #Turn on Verbose output if module was imported with -Verbose 5 | if ($myinvocation.line -match "Verbose") { 6 | $VerbosePreference = "Continue" 7 | } 8 | if ($IsWindows -OR $PSEdition -eq 'Desktop') { 9 | 10 | Write-Verbose "Dot source the module script files" 11 | (Get-ChildItem $PSScriptRoot\functions\*.ps1).foreach( { .$_.fullname }) 12 | 13 | Write-Verbose "Testing for Microsoft.WindowsTerminal" 14 | <# 15 | need to take into account that a user might have a preview version also installed 16 | of maybe they are only using the preview version. 17 | 8/1/2020 jdh 18 | #> 19 | 20 | #use the settings of the currently running Windows Terminal 21 | 22 | <# 23 | Sept. 22, 2020 JH 24 | PowerShell 7.1 previews are based on a newer version of .NET Core which breaks the AppX cmdlets. I'll use remoting to Windows PowerShell. 25 | #> 26 | if ($PSVersionTable.PSVersion.ToString() -match "^7\.[1-9]") { 27 | Write-Verbose "PowerShell 7.x detected. Using implicit remoting to get the Appx package." 28 | $app = Invoke-Command -ScriptBlock { Get-AppxPackage Microsoft.WindowsTerminal* } -ConfigurationName Microsoft.PowerShell -ComputerName localhost 29 | } 30 | else { 31 | $app = Get-AppxPackage Microsoft.WindowsTerminal* 32 | } 33 | 34 | if ($app) { 35 | Write-Verbose "Windows Terminal is installed" 36 | Write-Verbose "Testing for a current WindowsTerminal Process" 37 | $wt = Get-CimInstance -ClassName Win32_process -Filter "ProcessID=$pid" 38 | #validate the parent process is Windows Terminal 39 | $parent = Get-Process -Id $wt.parentProcessID 40 | 41 | #modified to take into account PowerShell previews which launch from a cmd script 12/18/2020 jdh 42 | if ($parent.processname -match "WindowsTerminal" -OR $parent.parent.processname -match "WindowsTerminal") { 43 | Write-Verbose "Testing for settings.json" 44 | <# 45 | #build path from process path 46 | $wtPath = Split-Path -Path $parent.path 47 | #pull the release name from $wtpath -parsing out version number 48 | $release = Split-Path -path $wtpath -leaf 49 | #$trimmed = $Release -replace "_.*_", "_" 50 | #> 51 | 52 | #The application name should be static 12/18/2020 jdh 53 | #need to account if using Preview 12/21/2020 jdh (Issue #13) 54 | if ($parent.path -match "WindowsTerminalPreview") { 55 | $jsonPath = "$ENV:Userprofile\AppData\Local\Packages\Microsoft.WindowsTerminalPreview*_8wekyb3d8bbwe\LocalState\settings.json" 56 | } 57 | else { 58 | $jsonPath = "$ENV:Userprofile\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" 59 | 60 | } 61 | Write-Verbose "Using path $jsonPath" 62 | If (Test-Path $jsonPath) { 63 | #Export settings path to a global variable 64 | Write-Verbose "Creating settings variable" 65 | $global:WTSettingsPath = $jsonPath 66 | 67 | #create a custom object with the settings.json values saved as $WTSettings 68 | AddWTSettingsVariable 69 | 70 | Write-Verbose "Creating a global variable with defaults" 71 | $defaults = Join-Path -Path $app.installLocation -ChildPath defaults.json 72 | $global:WTDefaultsPath = $defaults 73 | #need to account for preview and stable releases 74 | $global:WTDefaults = $defaults.foreach( { 75 | $wtPath = $_ 76 | (Get-Content -Path $_).where( { $_ -notmatch "(\/{2})(?=\s+)" }) | ConvertFrom-Json | 77 | Add-Member -MemberType NoteProperty -Name DefaultPath -Value $wtPath -PassThru 78 | }) 79 | } #if json file is found 80 | else { 81 | Write-Verbose "Failed to find $jsonPath" 82 | } 83 | } #if parent process is WT 84 | else { 85 | Write-Verbose "Failed to find WindowsTerminal as the parent process." 86 | } 87 | } #if $app 88 | else { 89 | Write-Warning "Windows Terminal was not found on this system so not all commands in this module will work." 90 | } 91 | 92 | } #if Windows 93 | else { 94 | Write-Warning "This module requires a Windows platform." 95 | } 96 | #reset -Verbose if turned on 97 | if ($VerbosePreference -eq 'Continue') { 98 | Write-Verbose "Resetting verbose preference" 99 | $VerbosePreference = "SilentlyContinue" 100 | } 101 | #endregion 102 | 103 | #region completers 104 | 105 | 106 | Register-ArgumentCompleter -CommandName Get-WTProfile -ParameterName Name -ScriptBlock { 107 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 108 | 109 | #PowerShell code to populate $wordtoComplete 110 | 111 | $global:wtsettings.profiles.list | 112 | where-object {$_.name -like "*$wordtoComplete*"} | 113 | ForEach-Object { 114 | # completion text,listitem text,result type,Tooltip 115 | [System.Management.Automation.CompletionResult]::new("'$($_.name)'", $_.name, 'ParameterValue', $(if ($_.hidden) {"Hidden"} else {"Listed"})) 116 | } 117 | } 118 | 119 | 120 | Register-ArgumentCompleter -CommandName Get-WTColorScheme -ParameterName Name -ScriptBlock { 121 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 122 | 123 | #PowerShell code to populate $wordtoComplete 124 | 125 | $global:wtsettings.schemes | 126 | where-object {$_.name -like "*$wordtoComplete*"} | 127 | ForEach-Object { 128 | # completion text,listitem text,result type,Tooltip 129 | [System.Management.Automation.CompletionResult]::new("'$($_.name)'", $_.name, 'ParameterValue', $_.name) 130 | } 131 | } 132 | 133 | #endregion -------------------------------------------------------------------------------- /functions/private.ps1: -------------------------------------------------------------------------------- 1 | 2 | #a private helper function to parse the key settings into more manageable objects 3 | #this is called in Get-WTKeyBinding 4 | 5 | Function parsesetting { 6 | [cmdletbinding()] 7 | param( 8 | [parameter(Mandatory, ValueFromPipeline)] 9 | [object]$Setting) 10 | 11 | Process { 12 | if ($setting.command -is [string]) { 13 | $cmd = $setting.command 14 | #assuming there is only a single key binding 15 | #it is also possible the json file may use array syntax 16 | #even though a single key combination is specified 17 | $keys = $setting.keys | Select-Object -First 1 18 | $actionsettings = $null 19 | } 20 | else { 21 | $cmd = $setting.command.action 22 | $keys = $Setting.keys | Select-Object -First 1 23 | #join other action settings into a string 24 | $other = $setting.command.psobject.properties.where( { $_.name -ne 'action' }) | ForEach-Object { "$($_.Name) = $($_.value)" } 25 | $actionsettings = $other -join ";" 26 | } 27 | [pscustomobject]@{ 28 | Action = $cmd 29 | ActionSettings = $actionsettings 30 | Keys = $keys 31 | } 32 | } 33 | } 34 | 35 | Function AddWTSettingsVariable { 36 | [cmdletbinding()] 37 | Param() 38 | 39 | Write-Verbose "Parsing $global:WTSettingsPath" 40 | #need to strip out comments for Windows PowerShell 41 | #$pattern = "(?(?<=:|\/)no)(\/{2})(?=\s+)?" 42 | $pattern = "(\/{2})(?=\s+)?" 43 | Try { 44 | $obj = (Get-Content -Path $Global:WTSettingsPath).where({ $_ -notmatch $pattern -OR $_ -match "ms-appx:\/{3}" }) | ConvertFrom-Json -ErrorAction Stop 45 | } 46 | Catch { 47 | Write-Warning "Failed to parse settings.json. You might have an error in the file. $($_.Exception.Message)" 48 | } 49 | #only continue if there is an object 50 | if ($obj) { 51 | Write-Verbose "Adding custom properties" 52 | Add-Member -InputObject $obj -MemberType NoteProperty -Name Computername -Value $env:COMPUTERNAME 53 | Add-Member -InputObject $obj -MemberType NoteProperty -Name LastUpdated -Value ((Get-Item -Path $Global:WTSettingsPath).LastWriteTime) 54 | Add-Member -InputObject $obj -MemberType NoteProperty -Name LastRefresh -Value (Get-Date) 55 | 56 | Write-Verbose "Adding a method to refresh the object" 57 | Add-Member -InputObject $obj -MemberType ScriptMethod -Name Refresh -Value { AddWTSettingsVariable } 58 | Write-Verbose "Setting the WTSettings variable in the global scope" 59 | Set-Variable -Name WTSettings -Scope Global -Value $obj 60 | } 61 | else { 62 | Write-Warning "Failed to create the settings object." 63 | } 64 | } 65 | 66 | Function GetWTPackage { 67 | [cmdletbinding()] 68 | Param([switch]$Preview) 69 | 70 | if ($Preview) { 71 | $name = "Microsoft.WindowsTerminalPreview" 72 | } 73 | else { 74 | $name = "Microsoft.WindowsTerminal" 75 | } 76 | <# 77 | Sept. 22, 2020 JH 78 | PowerShell 7.1 is based on a newer version of .NET Core which breaks the AppX cmdlets. I'll use remoting to Windows PowerShell. 79 | #> 80 | <# 81 | Dec. 29, 2021 JH 82 | PowerShell 7.2 gets around the Appx bug by using implicit remoting to Windows PowerShell 83 | which is what I am doing here. Leaving this code as-is. 84 | #> 85 | if ($PSVersionTable.PSVersion.ToString() -match "^7\.[1-9]") { 86 | Write-Verbose "[$((Get-Date).TimeofDay)] Detected PowerShell $($matches[0])" 87 | Invoke-Command -ScriptBlock { Get-AppxPackage $using:Name } -ConfigurationName Microsoft.PowerShell -ComputerName localhost 88 | } 89 | else { 90 | Get-AppxPackage -Name $name 91 | } 92 | } 93 | Function NewWTProfile { 94 | [cmdletbinding()] 95 | Param([object]$WTProfile) 96 | 97 | #$WTProfile is an object from $wtsettings.profiles.list that will be converted 98 | #into a strongly typed object. 99 | if ($wtProfile.commandline) { 100 | $cmd = $wtProfile.commandline 101 | } 102 | else { 103 | $cmd = $wtProfile.source 104 | } 105 | if ($null -eq $wtprofile.hidden) { 106 | $hidden = $false 107 | } 108 | else { 109 | $hidden = $wtProfile.hidden 110 | } 111 | [pscustomobject]@{ 112 | PSTypeName = "wtProfile" 113 | Name = $wtProfile.Name 114 | Guid = $wtProfile.guid 115 | Hidden = $Hidden 116 | Title = $wtProfile.tabTitle 117 | SourceCommand = $cmd 118 | Icon = $WTProfile.Icon 119 | StartingDirectory = $WTProfile.StartingDirectory 120 | ColorScheme = $WTProfile.ColorScheme 121 | UseAcrylic = $WTProfile.UseAcrylic 122 | AcrylicOpacity = $WTProfile.AcrylicOpacity 123 | CursorShape = $wtProfile.CursorShape 124 | IsDefault = ($WTProfile.guid -eq $wtsettings.defaultProfile) 125 | } 126 | 127 | } 128 | 129 | 130 | Function Convert-HtmlToAnsi { 131 | [cmdletbinding()] 132 | [OutputType("string")] 133 | [alias("cha")] 134 | Param( 135 | [Parameter( 136 | Position = 0, 137 | Mandatory, 138 | ValueFromPipeline, 139 | HelpMessage = "Specify an HTML color code like #13A10E" 140 | )] 141 | [ValidatePattern('^#\w{6}')] 142 | [string]$HTMLCode 143 | ) 144 | Begin { 145 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" 146 | } #begin 147 | 148 | Process { 149 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Converting $HTMLCode" 150 | $c = [System.Drawing.ColorTranslator]::FromHtml($htmlCode) 151 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] RGB = $($c.r),$($c.g),$($c.b)" 152 | $ansi = '[38;2;{0};{1};{2}m' -f $c.R,$c.G,$c.B 153 | $ansi 154 | } #process 155 | End { 156 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" 157 | 158 | } #end 159 | } #close Convert-HTMLtoANSI 160 | 161 | -------------------------------------------------------------------------------- /functions/Get-WTKeybindings.ps1: -------------------------------------------------------------------------------- 1 | Function Get-WTKeyBinding { 2 | [cmdletbinding()] 3 | [outputtype("wtKeybinding")] 4 | [alias("gwtk")] 5 | Param( 6 | [Parameter(HelpMessage = "Select an action type.")] 7 | [ArgumentCompleter( { 'adjustFontSize', 'closeOtherTabs', 'closePane', 'closeTabsAfter', 'closeWindow', 'commandPalette', 'copy', 'duplicateTab', 'find', 'moveFocus', 'newTab', 'nextTab', 'openNewTabDropdown', 'openSettings', 'openTabColorPicker', 'paste', 'prevTab', 'resetFontSize', 'resizePane', 'scrollDown', 'scrollDownPage', 'scrollUp', 'scrollUpPage', 'splitPane', 'switchToTab', 'toggleAlwaysOnTop', 'toggleFocusMode', 'toggleFullscreen', 'togglePaneZoom', 'toggleRetroEffect' })] 8 | [ValidateNotNullOrEmpty()] 9 | [string]$Action 10 | ) 11 | 12 | Write-Verbose "[$((Get-Date).TimeofDay)] Starting $($MyInvocation.MyCommand)" 13 | #use a list object to make it easier to remove duplicate keybindings 14 | $list = [System.Collections.Generic.List[PSObject]]::new() 15 | 16 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting WindowsTerminal Appx package" 17 | <# 18 | Need to get the correct application depending on whether running release or preview 19 | #> 20 | if ((Get-WTProcess | Where-Object { $_.name -eq 'WindowsTerminal' }).path -match 'preview') { 21 | $install = (GetWTPackage -preview).installLocation 22 | } 23 | else { 24 | $install = (GetWTPackage).installLocation 25 | } 26 | 27 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting defaults.json file" 28 | $defaults = Join-Path -Path $install -ChildPath defaults.json 29 | 30 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting default Windows Terminal settings from $defaults" 31 | #strip out the // comments since they aren't valid json 32 | $defaultsettings = Get-Content -Path $defaults | Where-Object { $_ -notmatch "//" } | ConvertFrom-Json 33 | 34 | #get the keybindings and add a property that indicates where the setting came from. 35 | Write-Verbose "[$((Get-Date).TimeofDay)] Parsing default keybindings" 36 | <# 37 | It looks like the json schema might be changing so I need to allow for name variations. 38 | 8/1/2020 jdh 39 | 40 | Default keybindings are now defined under "actions" 9/22/2020 jdh 41 | #> 42 | Write-Verbose "[$((Get-Date).TimeofDay)] Detected $($defaultsettings.actions.count) default keybindings" 43 | if ($Action) { 44 | Write-Verbose "[$((Get-Date).TimeofDay)] Filtering for action $Action" 45 | #$defaultsettings.actions | out-string | write-Verbose 46 | 47 | #Windows PowerShell needs some help in unrolling collections so I'll explicitly cast this to an array of objects. 12/17/2020 jdh 48 | [object[]]$actionData = $defaultsettings.actions | Where-Object { $_.command -like $Action -OR $_.command.action -like $action } 49 | } 50 | else { 51 | [object[]]$actionData = $defaultsettings.actions 52 | } 53 | 54 | if ($actionData.count -gt 0) { 55 | Write-Verbose "[$((Get-Date).TimeofDay)] Parsing $($actionData.count) default items" 56 | 57 | [object[]]$keys = $actionData | parsesetting | Select-Object -Property *, @{Name = "Source"; Expression = { "Defaults" } } 58 | 59 | Write-Verbose "[$((Get-Date).TimeofDay)] Found $($keys.count) default keybindings" 60 | #add the keybinding objects to the list 61 | if ($keys.count -gt 0) { 62 | foreach ($k in $keys) { 63 | #adding individually to the list because of how $keys is getting generated, especially when filtering on an action 64 | #12/17/2020 jdh 65 | #insert a typename 12/18/2020 jdh 66 | #insert a typename 67 | $k.psobject.typenames.insert(0, "wtKeyBinding") 68 | $list.add($k) 69 | } 70 | } 71 | } 72 | else { 73 | Write-Warning "No matching actions found under default settings." 74 | } 75 | $settingsjson = $global:wtsettingspath 76 | Write-Verbose "[$((Get-Date).TimeofDay)] Getting user settings from $settingsjson" 77 | 78 | if (Test-Path -Path $settingsjson) { 79 | Write-Verbose "[$((Get-Date).TimeofDay)] Converting content to json" 80 | $settings = Get-Content -Path $settingsjson | Where-Object { $_ -notmatch "//" } | ConvertFrom-Json 81 | #this might change and be bindings or keybindings 82 | #only process if there are keybindings 83 | #based on new defaults it might also be "actions" 9/22/2020 jdh 84 | $bindProp = $settings.psobject.properties.name -match "(bindings)|(keybindings)|(actions)" 85 | $bind = $settings | Select-Object -ExpandProperty $bindProp[0] 86 | if ($bind) { 87 | if ($Action) { 88 | Write-Verbose "[$((Get-Date).TimeofDay)] Filtering for action $action" 89 | $bind = $bind | Where-Object { $_.command -like $Action -OR $_.command.action -like $Action } 90 | } 91 | 92 | $user = $bind | 93 | parsesetting | 94 | Select-Object -Property *, @{Name = "Source"; Expression = { "Settings" } } 95 | Write-Verbose "[$((Get-Date).TimeofDay)] Found $($keys.count) user keybindings" 96 | 97 | #if there is a duplicate key binding, remove the default 98 | foreach ($item in $user) { 99 | $existing = $list.where( { $_.keys -eq $item.keys }) 100 | if ($existing) { 101 | Write-Verbose "[$((Get-Date).TimeofDay)] Detected an override of $($existing| Out-String)" 102 | [void]($list.Remove($existing)) 103 | } 104 | #insert a typename 105 | $item.psobject.typenames.insert(0, "wtKeyBinding") 106 | #add the entry 107 | $list.Add($item) 108 | } 109 | } #if keybindings 110 | } 111 | 112 | if ($list.count -gt 0) { 113 | #write the keybinding objects to the pipeline 114 | #removed previous options to format results as part of the command. That was a poor Practice. 12/18/2020 jdh 115 | $list 116 | 117 | } 118 | else { 119 | Write-Warning "No matching key bindings found." 120 | } 121 | Write-Verbose "[$((Get-Date).TimeofDay)] Ending $($MyInvocation.MyCommand)" 122 | } -------------------------------------------------------------------------------- /formats/wtKeybinding.format.ps1xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | default 14 | 15 | wtKeyBinding 16 | 17 | 18 | 26 | Source 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 20 36 | left 37 | 38 | 39 | 40 | 40 41 | left 42 | 43 | 44 | 45 | 20 46 | left 47 | 48 | 49 | 50 | 51 | 52 | 53 | 57 | 58 | Action 59 | 60 | 61 | ActionSettings 62 | 63 | 64 | Keys 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | default 74 | 75 | wtKeyBinding 76 | 77 | 78 | 86 | Source 87 | 88 | 89 | 90 | 91 | 92 | 93 | 97 | 98 | 99 | Action 100 | 101 | 102 | 103 | ActionSettings 104 | 105 | 106 | 107 | Keys 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | keys 117 | 118 | wtKeyBinding 119 | 120 | 121 | 123 | 124 | 125 | 126 | 20 127 | left 128 | 129 | 130 | 131 | 40 132 | left 133 | 134 | 135 | 136 | 20 137 | left 138 | 139 | 140 | 141 | 10 142 | left 143 | 144 | 145 | 146 | 147 | 148 | 149 | 153 | 154 | Keys 155 | 156 | 157 | ActionSettings 158 | 159 | 160 | Action 161 | 162 | 163 | Source 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /functions/New-WTProfile.ps1: -------------------------------------------------------------------------------- 1 | Function New-WTProfile { 2 | [cmdletbinding(SupportsShouldProcess)] 3 | [outputtype("none")] 4 | Param( 5 | [Parameter( 6 | Position = 0, 7 | Mandatory, 8 | ValueFromPipelineByPropertyName, 9 | HelpMessage = "Specify the name of your new profile." 10 | )] 11 | [string]$Name, 12 | 13 | [Parameter( 14 | Mandatory, 15 | ValueFromPipelineByPropertyName, 16 | HelpMessage = "Specify the command-line to run" 17 | )] 18 | [string]$CommandLine, 19 | 20 | [Parameter( 21 | Mandatory, ValueFromPipelineByPropertyName, 22 | HelpMessage = "Specify the tab title" 23 | )] 24 | [alias("Title")] 25 | [string]$TabTitle, 26 | 27 | [Parameter(ValueFromPipelineByPropertyName,HelpMessage = "Specify a valid color scheme.")] 28 | [ArgumentCompleter({ $WTSettings.schemes.foreach({ 29 | if ($_.name -match "\s") { 30 | "'$($_.name)'" 31 | } 32 | else { 33 | $_.name 34 | } 35 | } 36 | )} 37 | )] 38 | [ValidateNotNullOrEmpty()] 39 | [string]$ColorScheme = "Campbell", 40 | 41 | [Parameter(ValueFromPipelineByPropertyName,HelpMessage = "Specify a cursor shape.")] 42 | [ValidateSet( "bar", 43 | "doubleUnderscore", 44 | "emptyBox", 45 | "filledBox", 46 | "underscore", 47 | "vintage")] 48 | [string]$CursorShape = "bar", 49 | 50 | [Parameter(ValueFromPipelineByPropertyName,HelpMessage = "Do you want the profile to be marked as hidden?")] 51 | [switch]$Hidden, 52 | 53 | [Parameter(ValueFromPipelineByPropertyName,HelpMessage = "Specify a starting directory like %WINDIR% or C:\Work")] 54 | [string]$StartingDirectory = "%USERPROFILE%", 55 | 56 | [Parameter(ValueFromPipelineByPropertyName,HelpMessage = "Do you want to enable acrylic settings?")] 57 | [switch]$UseAcrylic, 58 | 59 | [Parameter(ValueFromPipelineByPropertyName,HelpMessage = "If you enable acrylic settings you can specify a value.")] 60 | [ValidateRange(0.1, 1)] 61 | [double]$AcrylicOpacity = "1.0", 62 | 63 | [Parameter(ValueFromPipelineByPropertyName,HelpMessage = "Specify the path to a background image.")] 64 | [ValidateScript({ 65 | if ($_ -match "\w+") { 66 | $test = Test-Path $_ 67 | if ($test) { 68 | $True 69 | } 70 | else { 71 | Throw "Can't find the image file $_" 72 | } 73 | } 74 | else { 75 | $True 76 | } 77 | })] 78 | [alias("bg")] 79 | [string]$BackgroundImage, 80 | 81 | [Parameter(ValueFromPipelineByPropertyName,HelpMessage = "Specify the background image opacity.")] 82 | [ValidateRange(0.1, 1)] 83 | [alias("bgopacity")] 84 | [double]$BackgroundImageOpacity = 1.0, 85 | 86 | [Parameter(ValueFromPipelineByPropertyName,HelpMessage = "Specify the background image stretch mode.")] 87 | [validateSet( 88 | "fill", 89 | "none", 90 | "uniform", 91 | "uniformToFill" 92 | )] 93 | [alias("bgstretch")] 94 | [string]$BackgroundImageStretchMode = "none", 95 | 96 | [Parameter(ValueFromPipelineByPropertyName,HelpMessage = "Specify the background image alignment.")] 97 | [ValidateSet( 98 | "bottom", 99 | "bottomLeft", 100 | "bottomRight", 101 | "center", 102 | "left", 103 | "right", 104 | "top", 105 | "topLeft", 106 | "topRight" 107 | )] 108 | [alias("bgalign")] 109 | [string]$BackgroundImageAlignment = "center" 110 | ) 111 | Begin { 112 | Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" 113 | #get existing names 114 | $current = $wtsettings.profiles.list.name 115 | #get current settings in a list 116 | $list = [System.Collections.Generic.list[string]]::new() 117 | Get-Content $wtsettingspath | foreach-object { 118 | $list.add($_) 119 | } 120 | #this list will hold the new profiles 121 | $add = [System.Collections.Generic.list[string]]::new() 122 | } #begin 123 | 124 | Process { 125 | Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Creating Windows Terminal profile $Name " 126 | if ($current -contains $Name) { 127 | Write-Warning "There is already a profile with the name of $name." 128 | #bail out 129 | return 130 | } 131 | if ($BackgroundImage) { 132 | $BackgroundImage = Convert-Path $BackgroundImage 133 | } 134 | $new = [pscustomobject]@{ 135 | commandline = $CommandLine 136 | name = $Name 137 | guid = "{$((New-Guid).ToString())}" 138 | tabTitle = $TabTitle 139 | colorScheme = $colorScheme 140 | hidden = $($Hidden -as [bool]) 141 | startingDirectory = $StartingDirectory 142 | useAcrylic = $($useAcrylic -as [bool]) 143 | acrylicOpacity = $acrylicOpacity 144 | cursorShape = $cursorShape 145 | backgroundImage = $BackgroundImage 146 | backgroundImageOpacity = $BackgroundImageOpacity 147 | backgroundImageStretchMode = $BackgroundImageStretchMode 148 | backgroundImageAlignment = $backgroundImageAlignment 149 | } | ConvertTo-Json 150 | 151 | if ($pscmdlet.ShouldProcess($name)) { 152 | $new.split("`r`n") | Foreach-Object {$add.add($_)} 153 | #add the closing comma 154 | $add[-1] = "$($new[-1])," 155 | Write-Verbose ($add | Out-String) 156 | } 157 | } #process 158 | 159 | End { 160 | $i = $list.FindIndex({$args[0] -match '"list":'}) 161 | #now find the opening [ 162 | While ($list[$i] -notmatch "\[") { 163 | $i++ 164 | } 165 | #insert the new profile(s) here 166 | $list.InsertRange($i+1,$add) 167 | #update the settings file 168 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Update settings.json" 169 | $list | Out-File -FilePath $WTsettingsPath 170 | Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" 171 | } #end 172 | 173 | } #close New-WTProfile -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Change Log for WTToolBox 2 | 3 | ## v1.15.0 4 | 5 | + Fixed installation bug in `Install-WTRelease`. Need to account for Windows 10 or Windows 11 bundle. 6 | + Updated `README.md` 7 | 8 | ## v1.14.0 9 | 10 | This is a significant upgrade with many new commands. It is assumed you are running a recent version of Windows Terminal and that your profile uses `List` configuration. Early versions used a different layout in the settings.json file. 11 | 12 | + Added command `Get-WTProfile`. 13 | + Added new object `wtProfile` to `Get-WTCurrent`. 14 | + Added private function `NewWTProfile` to create `wtprofile` objects. 15 | + Added format file `wtprofile.format.ps1xml` for the new object type. 16 | + Added command `Set-WTDefaultProfile` to set default Windows Terminal profile. 17 | + Added command `Get-WTColorScheme` and private function `Convert-HtmltoAnsi`. 18 | + Added format file `wtcolorscheme.format.ps1xml`. 19 | + Added command `New-WTProfile` to create a new profile in the settings.json file. 20 | + Added commands `Export-WTProfile` and `Import-WTProfile`. 21 | + Help updates. 22 | + Updated `README.md`. 23 | 24 | ## v1.13.0 25 | 26 | + Updated `Get-WTProcess` to better handle PowerShell 7 preview sessions. This also fixes a related bug with `Open-WTDefault`. (Issue #11) 27 | + Added new table view called `keys` for `WTKeybinding` objects. 28 | + Updated table view in `wtKeybinding.format.ps1xml` to use static column widths. 29 | + Added `Test-IsWTPreview` as an exported function. 30 | + Help updates. 31 | + Updated Pester Tests 32 | 33 | ## v1.12.0 34 | 35 | + Updated `Get-WTKeybinding` to better handle errors when action type not found. (Issue #10) 36 | + Fixed issue when importing the module running the Preview version of Windows Terminal. (Issue #13) 37 | + Added private function `Test-IsWTPreview`. 38 | + Updated `Test-WTVersion` to better handle Windows Terminal Preview. 39 | 40 | ## v1.11.1 41 | 42 | + Updated module file to handle failures with the Appx commands in PowerShell 7.1 and later. This will rely on using a remote connection to the Windows PowerShell installation on the local host. If PowerShell remoting is not enabled, this may not work. (Issue #9) 43 | + Modified module file to use a static value for part of the JSON settings path. 44 | + Fixed bug in module file that was not resetting Verbose preference. 45 | + Updated private function `GetWTPackage` to better handle PowerShell 7.x releases and the Appx bug. 46 | 47 | ## v1.11.0 48 | 49 | + Fixed IconUri in the module manifest. 50 | + Modified `Get-WTKeyBinding` to let the user filter on an action. 51 | + Modified `Get-WTKeyBinding` to write a structured object with a typename of `wtKeybinding` to the pipeline. Removed the `Format` parameter. _This is a breaking change_. 52 | + Added a custom format file `wtKeybinding.format.ps1xml`. 53 | + Added an `about_WTToolBox` help topic. 54 | 55 | ## v1.10.1 56 | 57 | + Added better error handling when encountering bad JSON. (Issue #8) 58 | + Minor updates to `README.md`. 59 | 60 | ## 1.10.0 61 | 62 | + Added a private function called `GetWTPackage` to get the Windows Terminal Appx package. This command will fall back to PowerShell Remoting when running PowerShell 7.1. 63 | + Updated `Get-WTKeyBindings` to handle property name change to `Action` for default keybindings. 64 | + Fixed a bug in `Get-WTReleaseNote` to separate preview and stable releases. 65 | + Updated `README.md`. 66 | 67 | ## 1.9.1 68 | 69 | + Forgot to define the `gwtc` alias. 70 | + Added an alias `gwtk` for `Get-WTKeyBinding`. 71 | + Added an alias `bwt` for `Backup-WTSetting`. 72 | + Updated `README.md`. 73 | + Help updates. 74 | 75 | ## 1.9.0 76 | 77 | + Fixed bug that was causing `Install-WTRelease` to fail. (Issue #7) 78 | + Added an alias `Install-WindowsTerminal` for `Install-WTRelease`. 79 | + Added an alias `gwtp` for `Get-WTProcess`. 80 | + Added an alias `gwtc` for `Get-WTCurrent`. 81 | 82 | ## 1.8.0 83 | 84 | + 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) 85 | + Updated the `WTDefaults` global variable to include the path and to accommodate multiple installed releases. 86 | + Revised `Open-WTDefault` to only run in a Windows Terminal session and to better detect if running under preview or stable release. 87 | + Added a `-Preview` parameter to `Get-WTReleaseNote` to retrieve the release note from the latest preview. 88 | + Revised `Get-WTKeyBinding` to handle possible property name change of `keybindings` to `bindings`. 89 | + Help updates 90 | 91 | ## 1.7.0 92 | 93 | + Fixed bug in `Install-WTToolbox` that was breaking the installation. 94 | + Minor grammar corrections to the `README.md`. 95 | 96 | ## 1.6.0 97 | 98 | + Modified by `Get-WTCurrent` to work when the settings file is based on defaults. (Issue #2) 99 | + Modified the regex pattern used to filter out comments to not require a space after //. 100 | + Added online links to help documentation. 101 | + Fixed typo in `AddWTSettingsVariable` that was preventing LastUpdated and LastRefresh properties from being defined. 102 | + Fixed typo in `Backup-WTSetting` that was not sorting backup files properly. 103 | + Updated `README.md` 104 | 105 | ## 1.5.0 106 | 107 | + Added `Install-WTRelease` (Issue #4) 108 | + Added `Get-WTCurrentRelease` (Issue #3) 109 | + Updated warning on module import. 110 | + Updated `README.md` 111 | + Help updates 112 | 113 | ## 1.4.0 114 | 115 | + Modified `Get-WTReleaseNote` to release objects, not pre-release. 116 | + Update `Get-WTReleaseNote` to include an `-Online` parameter to open the release notes in GitHub. 117 | + Updated Pester tests. 118 | 119 | ## 1.3.0 120 | 121 | + Modified code that generates `$WTSettings` and `WTDefaults` to not strip out icons and other content with // in the path. 122 | + Added `$WTDefaultsPath` variable. 123 | + Modified `Get-WTProcess` to write a custom object type to the pipeline. 124 | + Added `wtprocess.format.ps1xml` to format the current process process in green. 125 | + Added `Get-WTCurrent` command to display profile settings for the current PowerShell window. 126 | + Standardized verbose messages. 127 | + Updated `README.md`. 128 | 129 | ## 1.2.0 130 | 131 | + Added 'Get-WTReleaseNote` 132 | + Updated Pester test 133 | + Modified private function `AddWTSettingsVariable` to solve `Add-Member` problem. (Issue #1) 134 | + Modified `WTToolbox.psm1` to add Verbose support 135 | 136 | ## 1.1.0 137 | 138 | + Added `Test-WTVersion`. 139 | + Modified module to create a global variable `$WTSettings` with a converted version of `settings.json`. 140 | + Modified module to create a global variable `WTSettingsPath` with the path to the `setting.json` file. 141 | + Modified module to create a global variable `$WTDefaults` with a converted version of `defaults.json`. 142 | + Added a private function called `AddWTSettingsVariable. 143 | + Updated `README.md`. 144 | + Minor help revisions 145 | + Updated Pester test file 146 | 147 | ## 1.0.0 148 | 149 | + Updated module manifest 150 | + Published to the PowerShell Gallery 151 | + Added placeholder `readme.txt` files in unused folders 152 | + Refactored commands for better Pester testing 153 | + Added Pester tests for the module and commands 154 | 155 | ## 0.2.0 156 | 157 | + Updated `Get-WTProcess` to work in both Windows PowerShell and PowerShell 7 158 | + Updated `Get-WTProcess` to display results sorted by CreationDate 159 | + Added help documentation 160 | 161 | ## 0.1.0 162 | 163 | + initial files 164 | -------------------------------------------------------------------------------- /docs/New-WTProfile.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: WTToolBox-help.xml 3 | Module Name: WTToolBox 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # New-WTProfile 9 | 10 | ## SYNOPSIS 11 | 12 | Create a new Windows Terminal profile. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | New-WTProfile [-Name] -CommandLine -TabTitle [-ColorScheme ] [-CursorShape ] [-Hidden] [-StartingDirectory ] [-UseAcrylic] [-AcrylicOpacity ] [-BackgroundImage ] [-BackgroundImageOpacity ] [-BackgroundImageStretchMode ] [-BackgroundImageAlignment ] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | New-WTProfile makes it easier to create a custom Windows Terminal profile from a PowerShell prompt. Not every single setting is available, but enough to accomplish the bulk of the setting. Most of the parameters accept pipeline input so you can pipe an object with matching parameter names to New-WTProfile. 23 | 24 | The new profile will be inserted at the top of the list in the settings.json file. 25 | 26 | ## EXAMPLES 27 | 28 | ### Example 1 29 | 30 | ```powershell 31 | PS C:\> New-WTProfile -Name CMD -CommandLine cmd.exe -TabTitle Windows -CursorShape vintage -StartingDirectory "%WINDIR%" 32 | ``` 33 | 34 | Create a new profile called CMD that will run cmd.exe starting in the Windows directory. 35 | 36 | ## PARAMETERS 37 | 38 | ### -AcrylicOpacity 39 | 40 | If you enable acrylic settings you can specify a value. 41 | 42 | ```yaml 43 | Type: Double 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: False 48 | Position: Named 49 | Default value: 1.0 50 | Accept pipeline input: True (ByPropertyName) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -BackgroundImage 55 | 56 | Specify the path to a background image. 57 | 58 | ```yaml 59 | Type: String 60 | Parameter Sets: (All) 61 | Aliases: bg 62 | 63 | Required: False 64 | Position: Named 65 | Default value: None 66 | Accept pipeline input: True (ByPropertyName) 67 | Accept wildcard characters: False 68 | ``` 69 | 70 | ### -BackgroundImageAlignment 71 | 72 | Specify the background image alignment. 73 | 74 | ```yaml 75 | Type: String 76 | Parameter Sets: (All) 77 | Aliases: bgalign 78 | Accepted values: bottom, bottomLeft, bottomRight, center, left, right, top, topLeft, topRight 79 | 80 | Required: False 81 | Position: Named 82 | Default value: center 83 | Accept pipeline input: True (ByPropertyName) 84 | Accept wildcard characters: False 85 | ``` 86 | 87 | ### -BackgroundImageOpacity 88 | 89 | Specify the background image opacity. 90 | 91 | ```yaml 92 | Type: Double 93 | Parameter Sets: (All) 94 | Aliases: bgopacity 95 | 96 | Required: False 97 | Position: Named 98 | Default value: 1.0 99 | Accept pipeline input: True (ByPropertyName) 100 | Accept wildcard characters: False 101 | ``` 102 | 103 | ### -BackgroundImageStretchMode 104 | 105 | Specify the background image stretch mode. 106 | 107 | ```yaml 108 | Type: String 109 | Parameter Sets: (All) 110 | Aliases: bgstretch 111 | Accepted values: fill, none, uniform, uniformToFill 112 | 113 | Required: False 114 | Position: Named 115 | Default value: None 116 | Accept pipeline input: True (ByPropertyName) 117 | Accept wildcard characters: False 118 | ``` 119 | 120 | ### -ColorScheme 121 | 122 | Specify a valid color scheme. You should be able to tab-complete through the list of defined schemes. 123 | 124 | ```yaml 125 | Type: String 126 | Parameter Sets: (All) 127 | Aliases: 128 | 129 | Required: False 130 | Position: Named 131 | Default value: Campbell 132 | Accept pipeline input: True (ByPropertyName) 133 | Accept wildcard characters: False 134 | ``` 135 | 136 | ### -CommandLine 137 | 138 | Specify the command-line to run 139 | 140 | ```yaml 141 | Type: String 142 | Parameter Sets: (All) 143 | Aliases: 144 | 145 | Required: True 146 | Position: Named 147 | Default value: None 148 | Accept pipeline input: True (ByPropertyName) 149 | Accept wildcard characters: False 150 | ``` 151 | 152 | ### -Confirm 153 | 154 | Prompts you for confirmation before running the cmdlet. 155 | 156 | ```yaml 157 | Type: SwitchParameter 158 | Parameter Sets: (All) 159 | Aliases: cf 160 | 161 | Required: False 162 | Position: Named 163 | Default value: None 164 | Accept pipeline input: False 165 | Accept wildcard characters: False 166 | ``` 167 | 168 | ### -CursorShape 169 | 170 | Specify a cursor shape. 171 | 172 | ```yaml 173 | Type: String 174 | Parameter Sets: (All) 175 | Aliases: 176 | Accepted values: bar, doubleUnderscore, emptyBox, filledBox, underscore, vintage 177 | 178 | Required: False 179 | Position: Named 180 | Default value: bar 181 | Accept pipeline input: True (ByPropertyName) 182 | Accept wildcard characters: False 183 | ``` 184 | 185 | ### -Hidden 186 | 187 | Do you want the profile to be marked as hidden? 188 | 189 | ```yaml 190 | Type: SwitchParameter 191 | Parameter Sets: (All) 192 | Aliases: 193 | 194 | Required: False 195 | Position: Named 196 | Default value: None 197 | Accept pipeline input: True (ByPropertyName) 198 | Accept wildcard characters: False 199 | ``` 200 | 201 | ### -Name 202 | 203 | Specify the name of your new profile. 204 | 205 | ```yaml 206 | Type: String 207 | Parameter Sets: (All) 208 | Aliases: 209 | 210 | Required: True 211 | Position: 0 212 | Default value: None 213 | Accept pipeline input: True (ByPropertyName) 214 | Accept wildcard characters: False 215 | ``` 216 | 217 | ### -StartingDirectory 218 | 219 | Specify a starting directory like %WINDIR% or C:\Work 220 | 221 | ```yaml 222 | Type: String 223 | Parameter Sets: (All) 224 | Aliases: 225 | 226 | Required: False 227 | Position: Named 228 | Default value: %USERPROFILE% 229 | Accept pipeline input: True (ByPropertyName) 230 | Accept wildcard characters: False 231 | ``` 232 | 233 | ### -TabTitle 234 | 235 | Specify the tab title. 236 | 237 | ```yaml 238 | Type: String 239 | Parameter Sets: (All) 240 | Aliases: Title 241 | 242 | Required: True 243 | Position: Named 244 | Default value: None 245 | Accept pipeline input: True (ByPropertyName) 246 | Accept wildcard characters: False 247 | ``` 248 | 249 | ### -UseAcrylic 250 | 251 | Do you want to enable acrylic settings? 252 | 253 | ```yaml 254 | Type: SwitchParameter 255 | Parameter Sets: (All) 256 | Aliases: 257 | 258 | Required: False 259 | Position: Named 260 | Default value: None 261 | Accept pipeline input: True (ByPropertyName) 262 | Accept wildcard characters: False 263 | ``` 264 | 265 | ### -WhatIf 266 | 267 | Shows what would happen if the cmdlet runs. 268 | The cmdlet is not run. 269 | 270 | ```yaml 271 | Type: SwitchParameter 272 | Parameter Sets: (All) 273 | Aliases: wi 274 | 275 | Required: False 276 | Position: Named 277 | Default value: None 278 | Accept pipeline input: False 279 | Accept wildcard characters: False 280 | ``` 281 | 282 | ### CommonParameters 283 | 284 | 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). 285 | 286 | ## INPUTS 287 | 288 | ### System.String 289 | 290 | ### System.Management.Automation.SwitchParameter 291 | 292 | ### System.Double 293 | 294 | ## OUTPUTS 295 | 296 | ### none 297 | 298 | ## NOTES 299 | 300 | Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ 301 | 302 | ## RELATED LINKS 303 | 304 | [Set-WTDefaultProfile](Set-WTDefaultProfile.md) 305 | 306 | [Get-WTProfile](Get-WTProfile.md) 307 | 308 | [Import-WTProfile](Import-WTProfile.md) 309 | -------------------------------------------------------------------------------- /docs/about_WTToolbox.md: -------------------------------------------------------------------------------- 1 | # WTToolbox 2 | 3 | ## about_WTToolbox 4 | 5 | # SHORT DESCRIPTION 6 | 7 | The WTToolBox module is a set of PowerShell functions for managing and working 8 | with the Windows Terminal application from Microsoft. 9 | 10 | # LONG DESCRIPTION 11 | The module consists of these commands: 12 | 13 | Backup-WTSetting 14 | Get-WTKeyBinding 15 | Get-WTReleaseNote 16 | Get-WTProcess 17 | Get-WTCurrent 18 | Get-WTProfile 19 | Get-WTColorScheme 20 | Open-WTDefault 21 | Set-WTDefaultProfile 22 | Test-WTVersion 23 | Get-WTCurrentRelease 24 | Install-WTRelease 25 | Test-IsWTPreview 26 | Export-WTProfile 27 | Import-WTProfile 28 | New-WTProfile 29 | 30 | The help documentation and examples should be self-explanatory. 31 | 32 | ## Displaying Key Bindings 33 | 34 | Keeping track of all the possible keyboard shortcuts or keybindings can be 35 | difficult. Get-WTKeyBinding will go through all defined keybindings and 36 | display them. You can also select a specific action: 37 | 38 | PS C:\> Get-WTKeyBinding -Action *font* | Format-List 39 | 40 | Source: Defaults 41 | 42 | 43 | Action : adjustFontSize 44 | ActionSettings : delta = 1 45 | Keys : ctrl+= 46 | 47 | Action : adjustFontSize 48 | ActionSettings : delta = -1 49 | Keys : ctrl+- 50 | 51 | Action : resetFontSize 52 | ActionSettings : 53 | Keys : ctrl+0 54 | 55 | ## Getting Current Settings 56 | 57 | Use `Get-WTCurrent` to display the settings for the current PowerShell session 58 | in Windows Terminal. 59 | 60 | acrylicOpacity : 0.75 61 | commandline : C:\Program Files\PowerShell\7\pwsh.exe -nologo 62 | guid : {993855ad-b0eb-4f3d-8370-1a8d5b53abb5} 63 | icon : D:\OneDrive\windowsterminal\ProfileIcons\pwsh.scale-150.png 64 | name : PowerShell 7 65 | tabTitle : PS 7 66 | tabColor : #FFF000 67 | backgroundImage : D:\OneDrive\terminalthumbs\ps7now-orange-transparent.png 68 | backgroundImageAlignment : bottomRight 69 | backgroundImageStretchMode : none 70 | backgroundImageOpacity : 0.3 71 | useAcrylic : True 72 | 73 | ## Tracking Windows Terminal Version 74 | 75 | Because `Windows Terminal` can silently update, it may be awkward to know if 76 | you are running a new version. You might use the `Test-WTVersion` command in 77 | your PowerShell profile script like this: 78 | 79 | if ( $env:wt_session -AND (Test-WTVersion)) { 80 | Write-Host "A newer version of Windows Terminal is now installed." 81 | Start-Process https://github.com/microsoft/terminal/releases 82 | } 83 | 84 | On a related note, you can also use `Get-WTReleaseNote,` which will get the 85 | latest release information from the `Windows Terminal` GitHub repository. If 86 | you are running PowerShell 7.x, you can pipe the command to `Show-Markdown`. 87 | 88 | Get-WTReleaseNote | Show-Markdown -UseBrowser 89 | 90 | The document will have links to any referenced issues. 91 | 92 | You can also use Get-WTCurrentRelease to get a quick peek at the latest 93 | online version and your locally installed version. 94 | 95 | ## Windows Terminal Processes 96 | 97 | The `Get-WTProcess` command will get all processes associated with your 98 | Windows Terminal process. The output is a standard `System.Diagnostics.Process` 99 | object, but the default formatting has been customized to highlight the current 100 | PowerShell process. 101 | 102 | `Get-WTProcess` has an alias of `gwtp`. 103 | 104 | ## Global Variables 105 | 106 | To make it easier to see either default settings or your custom settings, when 107 | you import this module, it will define 3 global variables. Assuming, of course, 108 | that you have `Windows Terminal` installed and are using `settings.json`. 109 | 110 | ## WTSettingsPath 111 | 112 | The path to `settings.json` is buried in your `%AppData%` folder. You can use 113 | `$WTSettingsPath` as a placeholder. Yes, you can easily open the file from 114 | `Windows Terminal`, but there may be other things you want to do with the path 115 | information. 116 | 117 | ## WTDefaults 118 | 119 | You can use `$WTDefaults` as an object to view any number of default settings. 120 | Run `Open-WTDefaults` if you want to open the file in your code editor. 121 | 122 | ```powershell 123 | PS C:>\ $WTDefaults | Select-Object -property initial* 124 | 125 | initialCols initialRows 126 | ----------- ----------- 127 | 120 30 128 | ``` 129 | 130 | When you import the module, it will also create a variable called 131 | `$WTDefaultsPath,` which points to the `defaults.json` file. The variable makes 132 | it easier if you want to do something with it like make a copy. If you need to 133 | view the file, you can use the `Open-WTDefault` command. 134 | 135 | Note that if you have a preview release also installed, this variable will have 136 | two objects. 137 | 138 | ## WTSettings 139 | 140 | The last object is a customized version of the data in `settings.json`. 141 | `$WTSettings` should make it easier to see your settings. 142 | 143 | ```powershell 144 | PS C:\> $wtsettings.profiles.list | where-object hidden 145 | 146 | guid : {b453ae62-4e3d-5e58-b989-0a998ec441b8} 147 | hidden : True 148 | useAcrylic : False 149 | name : Azure Cloud Shell 150 | source : Windows.Terminal.Azure 151 | 152 | guid : {574e775e-4f2a-5b96-ac1e-a2962a402336} 153 | hidden : True 154 | name : PowerShell 155 | source : Windows.Terminal.PowershellCore 156 | 157 | guid : {6e9fa4d2-a4aa-562d-b1fa-0789dc1f83d7} 158 | hidden : True 159 | name : Legacy 160 | source : Windows.Terminal.Wsl 161 | 162 | guid : {c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40} 163 | hidden : True 164 | name : Ubuntu-18.04 165 | source : Windows.Terminal.Wsl 166 | ``` 167 | 168 | The object includes a few additional properties. The `LastUpdated` value is 169 | when `settings.json` was last revised. The `LastRefresh` value indicates when 170 | this object was created. Because you might modify your settings, after 171 | importing this module, there needed to be a mechanism to refresh the data. 172 | The custom object has a `Refresh()` method you can run at any time. 173 | 174 | ```powershell 175 | PS C:\> $WTSettings.refresh() 176 | ``` 177 | 178 | The method doesn't write anything to the pipeline. 179 | 180 | ### Caution 181 | 182 | A quick note on the `settings` and `default` objects. The JSON standard does 183 | not recognize comments, yet they are used in `Windows Terminal` settings files. 184 | You can see them with leading // characters. To avoid errors when converting 185 | the JSON to objects, these comments must be stripped out of the content. The 186 | clean-up process is done with a regular expression. PowerShell 7 is more 187 | forgiving if it detects comments. Windows PowerShell will refuse to convert the 188 | content from JSON. Although the module can handle JSON comments, the 189 | recommendation is that if you are using comments, that you insert a space after 190 | the leading slashes like this: `// this is a comment`. 191 | 192 | # NOTE 193 | 194 | If you have any suggestions for enhancements or bug reports, please use the 195 | Issues section of this repository: 196 | 197 | https://github.com/jdhitsolutions/WTToolbox/issues 198 | 199 | # SEE ALSO 200 | If you want to learn more about Windows Terminal, take a look at: 201 | 202 | https://devblogs.microsoft.com/commandline/getting-started-with-windows-terminal/ 203 | 204 | # KEYWORDS 205 | 206 | - Terminal 207 | - WindowsTerminal 208 | -------------------------------------------------------------------------------- /en-us/about_WTToolbox.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_wttoolbox 3 | 4 | SHORT DESCRIPTION 5 | The WTToolBox module is a set of PowerShell functions for managing and 6 | working with the Windows Terminal application from Microsoft. 7 | 8 | LONG DESCRIPTION 9 | The module consists of these commands: 10 | 11 | Backup-WTSetting 12 | Get-WTKeyBinding 13 | Get-WTReleaseNote 14 | Get-WTProcess 15 | Get-WTCurrent 16 | Get-WTProfile 17 | Get-WTColorScheme 18 | Open-WTDefault 19 | Set-WTDefaultProfile 20 | Test-WTVersion 21 | Test-IsWTPreview 22 | Get-WTCurrentRelease 23 | Install-WTRelease 24 | Export-WTProfile 25 | Import-WTProfile 26 | New-WTProfile 27 | 28 | The help documentation and examples should be self-explanatory. 29 | 30 | Displaying Key Bindings 31 | Keeping track of all the possible keyboard shortcuts or keybindings can be 32 | difficult. Get-WTKeyBinding will go through all defined keybindings and 33 | display them. You can also select a specific action: 34 | 35 | PS C:\> Get-WTKeyBinding -Action *font* | Format-List 36 | 37 | Source: Defaults 38 | 39 | 40 | Action : adjustFontSize 41 | ActionSettings : delta = 1 42 | Keys : ctrl+= 43 | 44 | Action : adjustFontSize 45 | ActionSettings : delta = -1 46 | Keys : ctrl+- 47 | 48 | Action : resetFontSize 49 | ActionSettings : 50 | Keys : ctrl+0 51 | 52 | Getting Current Settings 53 | Use Get-WTCurrent to display the settings for the current PowerShell 54 | session in Windows Terminal. 55 | 56 | acrylicOpacity : 0.75 57 | commandline : C:\Program Files\PowerShell\7\pwsh.exe -nologo 58 | guid : {993855ad-b0eb-4f3d-8370-1a8d5b53abb5} 59 | icon : D:\OneDrive\windowsterminal\ProfileIcons\pwsh.scale-150.png 60 | name : PowerShell 7 61 | tabTitle : PS 7 62 | tabColor : #FFF000 63 | backgroundImage : D:\OneDrive\terminalthumbs\ps7now-orange-transparent.png 64 | backgroundImageAlignment : bottomRight 65 | backgroundImageStretchMode : none 66 | backgroundImageOpacity : 0.3 67 | useAcrylic : True 68 | 69 | Tracking Windows Terminal Version 70 | Because Windows Terminal can silently update, it may be awkward to know if 71 | you are running a new version. You might use the Test-WTVersion command in 72 | your PowerShell profile script like this: 73 | 74 | if ($env:wt_session -AND Test-WTVersion) { 75 | Write-Host "A newer version of Windows Terminal is now installed." 76 | Start-Process https://github.com/microsoft/terminal/releases 77 | } 78 | 79 | On a related note, you can also use Get-WTReleaseNote, which will get the 80 | latest release information from the Windows Terminal GitHub repository. If 81 | you are running PowerShell 7.x, you can pipe the command to Show-Markdown. 82 | 83 | Get-WTReleaseNote | Show-Markdown -UseBrowser 84 | 85 | The document will have links to any referenced issues. 86 | You can also use Get-WTCurrentRelease to get a quick peek at the latest 87 | online version and your locally installed version. 88 | 89 | Windows Terminal Processes 90 | The Get-WTProcess command will get all processes associated with your 91 | Windows Terminal process. The output is a standard System.Diagnostics. 92 | Process object, but the default formatting has been customized to 93 | highlight the current PowerShell process. 94 | 95 | Get-WTProcess has an alias of gwtp. 96 | 97 | Global Variables 98 | To make it easier to see either default settings or your custom settings, 99 | when you import this module, it will define 3 global variables. Assuming, of 100 | course, that you have Windows Terminal installed and are using 101 | settings.json. 102 | 103 | WTSettingsPath 104 | The path to settings.json is buried in your %AppData% folder. You can 105 | use $WTSettingsPath as a placeholder. Yes, you can easily open the file 106 | from Windows Terminal, but there may be other things you want to do with 107 | the path information. 108 | 109 | WTDefaults 110 | You can use $WTDefaults as an object to view any number of default 111 | settings. Run Open-WTDefaults if you want to open the file in your code 112 | editor. 113 | 114 | PS C:>\ $WTDefaults | Select-Object -property initial* 115 | 116 | initialCols initialRows 117 | ----------- ----------- 118 | 120 30 119 | 120 | When you import the module, it will also create a variable called 121 | $WTDefaultsPath, which points to the defaults.json file. The variable 122 | makes it easier if you want to do something with it like make a copy. If you 123 | need to view the file, you can use the Open-WTDefault command. 124 | 125 | Note that if you have a preview release also installed, this variable will 126 | have two objects. 127 | 128 | WTSettings 129 | The last object is a customized version of the data in settings.json. 130 | $WTSettings should make it easier to see your settings. 131 | 132 | PS C:\> $wtsettings.profiles.list | where-object hidden 133 | 134 | guid : {b453ae62-4e3d-5e58-b989-0a998ec441b8} 135 | hidden : True 136 | useAcrylic : False 137 | name : Azure Cloud Shell 138 | source : Windows.Terminal.Azure 139 | 140 | guid : {574e775e-4f2a-5b96-ac1e-a2962a402336} 141 | hidden : True 142 | name : PowerShell 143 | source : Windows.Terminal.PowershellCore 144 | 145 | guid : {6e9fa4d2-a4aa-562d-b1fa-0789dc1f83d7} 146 | hidden : True 147 | name : Legacy 148 | source : Windows.Terminal.Wsl 149 | 150 | guid : {c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40} 151 | hidden : True 152 | name : Ubuntu-18.04 153 | source : Windows.Terminal.Wsl 154 | 155 | The object includes a few additional properties. The LastUpdated value is 156 | when settings.json was last revised. The LastRefresh value indicates 157 | when this object was created. Because you might modify your settings, after 158 | importing this module, there needed to be a mechanism to refresh the data. 159 | The custom object has a Refresh() method you can run at any time. 160 | 161 | PS C:\> $WTSettings.refresh() 162 | 163 | The method doesn't write anything to the pipeline. 164 | 165 | CAUTION 166 | A quick note on the settings and default objects. The JSON standard does 167 | not recognize comments, yet they are used in Windows Terminal settings 168 | files. You can see them with leading // characters. To avoid errors when 169 | converting the JSON to objects, these comments must be stripped out of the 170 | content. The clean-up process is done with a regular expression. PowerShell 171 | 7 is more forgiving if it detects comments. Windows PowerShell will refuse 172 | to convert the content from JSON. Although the module can handle JSON 173 | comments, the recommendation is that if you are using comments, that you 174 | insert a space after the leading slashes like this: // this is a comment. 175 | 176 | NOTE 177 | If you have any suggestions for enhancements or bug reports, please use the 178 | Issues section of this repository: 179 | 180 | https://github.com/jdhitsolutions/WTToolbox/issues 181 | 182 | SEE ALSO 183 | If you want to learn more about Windows Terminal, take a look at: 184 | https://devblogs.microsoft.com/commandline/getting-started-with-windows-terminal/ 185 | 186 | KEYWORDS 187 | - Terminal 188 | - WindowsTerminal 189 | -------------------------------------------------------------------------------- /formats/wtprocess.format.ps1xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | process 6 | 7 | WTProcess 8 | 9 | 10 | 11 | 12 | 13 | 14 | 7 15 | right 16 | 17 | 18 | 19 | 7 20 | right 21 | 22 | 23 | 24 | 8 25 | right 26 | 27 | 28 | 29 | 10 30 | right 31 | 32 | 33 | 34 | 5 35 | right 36 | 37 | 38 | 39 | 8 40 | right 41 | 42 | 43 | 44 | 6 45 | right 46 | 47 | 48 | 49 | 3 50 | right 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | if ($_.id -eq $pid) { 62 | "$([char]0x1b)[38;5;47m$($_.HandleCount)$([char]0x1b)[0m" 63 | } 64 | else { 65 | $_.HandleCount 66 | } 67 | 68 | 69 | 70 | 71 | $val = [long]($_.NPM / 1024) 72 | if ($_.id -eq $pid) { 73 | "$([char]0x1b)[38;5;47m$($val)$([char]0x1b)[0m" 74 | } 75 | else { 76 | $val 77 | } 78 | 79 | 80 | 81 | 82 | $val = [long]($_.PM / 1024) 83 | if ($_.id -eq $pid) { 84 | "$([char]0x1b)[38;5;47m$($val)$([char]0x1b)[0m" 85 | } 86 | else { 87 | $val 88 | } 89 | 90 | 91 | 92 | 93 | $val = [long]($_.WS / 1024) 94 | if ($_.id -eq $pid) { 95 | "$([char]0x1b)[38;5;47m$($val)$([char]0x1b)[0m" 96 | } 97 | else { 98 | $val 99 | } 100 | 101 | 102 | 103 | 104 | $val=[long]($_.VM / 1048576) 105 | if ($_.id -eq $pid) { 106 | "$([char]0x1b)[38;5;47m$($val)$([char]0x1b)[0m" 107 | } 108 | else { 109 | $val 110 | } 111 | 112 | 113 | 114 | 115 | if ($_.CPU -ne $()) 116 | { 117 | $val = $_.CPU.ToString("N") 118 | } 119 | if ($_.id -eq $pid) { 120 | "$([char]0x1b)[38;5;47m$($val)$([char]0x1b)[0m" 121 | } 122 | else { 123 | $val 124 | } 125 | 126 | 127 | 128 | 129 | if ($_.id -eq $pid) { 130 | "$([char]0x1b)[38;5;47m$($_.id)$([char]0x1b)[0m" 131 | } 132 | else { 133 | $_.id 134 | } 135 | 136 | 137 | 138 | 139 | if ($_.id -eq $pid) { 140 | "$([char]0x1b)[38;5;47m$($_.SI)$([char]0x1b)[0m" 141 | } 142 | else { 143 | $_.SI 144 | } 145 | 146 | 147 | 148 | 149 | if ($_.id -eq $pid) { 150 | "$([char]0x1b)[38;5;47m$($_.processname)$([char]0x1b)[0m" 151 | } 152 | else { 153 | $_.processname 154 | } 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WTToolBox 2 | 3 | [![PSGallery Version](https://img.shields.io/powershellgallery/v/WTToolbox.png?style=for-the-badge&logo=powershell&label=PowerShell%20Gallery)](https://www.powershellgallery.com/packages/WTToolBox/) [![PSGallery Downloads](https://img.shields.io/powershellgallery/dt/WTToolBox.png?style=for-the-badge&label=Downloads)](https://www.powershellgallery.com/packages/WTToolBox/) 4 | 5 | ![WindowsTerminal](assets/wt-icon.png) 6 | 7 | ## Windows Terminal Toolbox 8 | 9 | A set of PowerShell functions for managing and working with the [Windows Terminal](https://www.microsoft.com/store/productId/9N0DX20HK701) application from Microsoft. You can download the module from the PowerShell Gallery. This module should work on __Windows__ platforms under Windows PowerShell and PowerShell 7. 10 | 11 | ```powershell 12 | Install-Module WTToolBox [-scope CurrentUser] 13 | ``` 14 | 15 | Of course, it is assumed you have `Windows Terminal` installed, or you plan to install. If `Windows Terminal` is not installed, you will get a warning message when you import this module. 16 | 17 | If you want some background information on Windows Terminal, take a look at [https://devblogs.microsoft.com/commandline/getting-started-with-windows-terminal/](https://devblogs.microsoft.com/commandline/getting-started-with-windows-terminal/). 18 | 19 | ### __Important__ 20 | 21 | Windows Terminal is intended for use on a Windows 10 or Windows 11 desktop. In fact, it is now the default on Windows 11. You __cannot__ install Windows Terminal on Windows Server 2016 or 2019. Those platform do not meet the Windows Terminal minimal requirements. Based on [issues](https://github.com/microsoft/terminal/issues?q=is%3Aissue+windows+server+2022) in the Windows Terminal Github repository, Windows Terminal should install on Windows Server 2022 but there still appear to be compatibility issue. 22 | 23 | ## Module Commands 24 | 25 | * [Backup-WTSetting](docs/Backup-WTSetting.md) 26 | * [Export-WTProfile](docs/Export-WTProfile.md) 27 | * [Get-WTColorScheme](docs/Get-WTColorScheme.md) 28 | * [Get-WTCurrent](docs/Get-WTCurrent.md) 29 | * [Get-WTCurrentRelease](docs/Get-WTCurrentRelease.md) 30 | * [Get-WTKeyBinding](docs/Get-WTKeyBinding.md) 31 | * [Get-WTProcess](docs/Get-WTProcess.md) 32 | * [Get-WTProfile](docs/Get-WTProfile.md) 33 | * [Get-WTReleaseNote](docs/Get-WTReleaseNote.md) 34 | * [Import-WTProfile](docs/Import-WTProfile.md) 35 | * [Install-WTRelease](docs/Install-WTRelease.md) 36 | * [New-WTProfile](docs/New-WTProfile.md) 37 | * [Open-WTDefault](docs/Open-WTDefault.md) 38 | * [Set-WTDefaultProfile](docs/Set-WTDefaultProfile.md) 39 | * [Test-IsWTPreview](docs/Test-IsWTPreview.md) 40 | * [Test-WTVersion](docs/Test-WTVersion.md) 41 | 42 | ### Installing Windows Terminal 43 | 44 | You can install the latest stable or preview release of Windows Terminal using the packages available on GitHub. 45 | 46 | ```powershell 47 | Install-WTRelease [-preview] 48 | ``` 49 | 50 | The `Install-WTRelease` function has an alias of `Install-WindowsTerminal`. 51 | 52 | :warning: You can't install a version from within Windows Terminal because files will be in use. Close Windows Terminal and run `Install-WTRelease` in a traditional PowerShell window. 53 | 54 | ### Displaying Key Bindings 55 | 56 | Keeping track of all the possible keyboard shortcuts or keybindings can be difficult. `Get-WTKeyBinding` will go through all defined keybindings and display them. 57 | 58 | ```powershell 59 | PS C:\> Get-WTKeyBinding 60 | 61 | Source: Defaults 62 | 63 | Action ActionSettings Keys 64 | ------ -------------- ---- 65 | closeWindow alt+f4 66 | toggleFullscreen alt+enter 67 | toggleFullscreen f11 68 | toggleFocusMode 69 | toggleAlwaysOnTop 70 | openNewTabDropdown ctrl+shift+space 71 | openSettings ctrl+, 72 | openSettings target = defaultsFile ctrl+alt+, 73 | find ctrl+shift+f 74 | toggleRetroEffect 75 | ... 76 | 77 | Source: Settings 78 | 79 | Action ActionSettings Keys 80 | ------ -------------- ---- 81 | copy singleLine = False ctrl+c 82 | paste ctrl+v 83 | find ctrl+shift+f 84 | splitPane split = auto;splitMode = duplicate alt+shift+d 85 | newTab profile = Ubuntu ctrl+shift+u 86 | splitPane split = auto;profile = PS7 No ctrl+shift+> 87 | Profile;startingDirectory = 88 | C:\;tabTitle = PS7 Clean 89 | splitPane split = auto;profile = Windows ctrl+shift+< 90 | PowerShell No Profile;startingDirectory 91 | = C:\;tabTitle = PS Clean 92 | openTabColorPicker ctrl+/ 93 | ``` 94 | 95 | You can also select a specific action: 96 | 97 | ```poweshell 98 | PS C:\> Get-WTKeyBinding -Action *font* | Format-List 99 | 100 | Source: Defaults 101 | 102 | 103 | Action : adjustFontSize 104 | ActionSettings : delta = 1 105 | Keys : ctrl+= 106 | 107 | Action : adjustFontSize 108 | ActionSettings : delta = -1 109 | Keys : ctrl+- 110 | 111 | Action : resetFontSize 112 | ActionSettings : 113 | Keys : ctrl+0 114 | ``` 115 | 116 | ### Getting Current Settings 117 | 118 | Use `Get-WTCurrent` to display the settings for the current PowerShell session in Windows Terminal. 119 | 120 | ![Get-WTCurrent](assets/wtcurrent.png) 121 | 122 | ### Tracking Windows Terminal Releases 123 | 124 | 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: 125 | 126 | ```powershell 127 | if ( $env:wt_session -AND (Test-WTVersion)) { 128 | Write-Host "A newer version of Windows Terminal is now installed." -foreground Yellow 129 | Start-Process https://github.com/microsoft/terminal/releases 130 | } 131 | ``` 132 | 133 | 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`. 134 | 135 | ```powershell 136 | Get-WTReleaseNote | Show-Markdown -UseBrowser 137 | ``` 138 | 139 | The document will have links to any referenced issues. 140 | 141 | You can also use [Get-WTCurrentRelease](docs/Get-WTCurrentRelease.md) to get a quick peek at the latest online version and your locally installed version. 142 | 143 | ```powershell 144 | PS C:\> Get-WTCurrentRelease 145 | 146 | Name Version Released LocalVersion 147 | ---- ------- -------- ------------ 148 | Windows Terminal v1.13.1143 v1.13.11431.0 5/24/2022 5:01:48 PM 1.13.11432.0 149 | ``` 150 | 151 | ### Windows Terminal Processes 152 | 153 | 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. 154 | 155 | ![Get-WTProcess](assets/wtprocess-ansi.png) 156 | 157 | `Get-WTProcess` has an alias of `gwtp`. 158 | 159 | ## Global Variables 160 | 161 | To make it easier to see either default settings or your custom settings, when you import this module, it will define 3 global variables. Assuming, of course, that you have `Windows Terminal` installed and are using `settings.json`. 162 | 163 | ### WTSettingsPath 164 | 165 | The path to `settings.json` is buried in your `%AppData%` folder. You can use `$WTSettingsPath` as a placeholder. Yes, you can easily open the file from `Windows Terminal`, but there may be other things you want to do with the path information. 166 | 167 | ### WTDefaults 168 | 169 | You can use `$WTDefaults` as an object to view any number of default settings. Use `Open-WTDefaults` if you want to open the file in your code editor. 170 | 171 | ```powershell 172 | PS C:>\ $WTDefaults | Select-Object -property initial* 173 | 174 | initialCols initialRows 175 | ----------- ----------- 176 | 120 30 177 | ``` 178 | 179 | 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](docs/Open-WTDefault.md) command. 180 | 181 | > If you have a preview release also installed, this variable will have two objects. 182 | 183 | ### WTSettings 184 | 185 | The last object is a customized version of the data in `settings.json`. `$WTSettings` should make it easier to see your settings. 186 | 187 | ```powershell 188 | PS C:\> $wtsettings.profiles.list | Where-Object hidden 189 | 190 | guid : {b453ae62-4e3d-5e58-bget989-0a998ec441b8} 191 | hidden : True 192 | useAcrylic : False 193 | name : Azure Cloud Shell 194 | source : Windows.Terminal.Azure 195 | 196 | guid : {574e775e-4f2a-5b96-ac1e-a2962a402336} 197 | hidden : True 198 | name : PowerShell 199 | source : Windows.Terminal.PowershellCore 200 | 201 | guid : {6e9fa4d2-a4aa-562d-b1fa-0789dc1f83d7} 202 | hidden : True 203 | name : Legacy 204 | source : Windows.Terminal.Wsl 205 | 206 | guid : {c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40} 207 | hidden : True 208 | name : Ubuntu-18.04 209 | source : Windows.Terminal.Wsl 210 | ``` 211 | 212 | The object includes a few additional properties. 213 | 214 | ![wtsettings](assets/wtsettings.png) 215 | 216 | The `LastUpdated` value is when `settings.json` was last revised. The `LastRefresh` value indicates when this object was created. Because you might modify your settings, after importing this module, there needed to be a mechanism to refresh the data. The custom object has a `Refresh()` method you can run at any time. 217 | 218 | ```powershell 219 | PS C:\> $WTSettings.refresh() 220 | ``` 221 | 222 | The method doesn't write anything to the pipeline. 223 | 224 | _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 can handle JSON comments, the recommendation is that if you are using comments, that you insert a space after the leading slashes like this: `// this is a comment`._ 225 | 226 | ## Windows Terminal Profiles 227 | 228 | Beginning with version 1.14.0 of this module, you can use PowerShell functions to manage Windows Terminal profiles instead of relying on the module variables like `$wtsettings`. 229 | 230 | ### Getting Windows Terminal Profiles 231 | 232 | You can use [Get-WTProfile](docs/Get-WTProfile.md) to return all defined Windows Terminal Profiles. The default behavior is to get all non-hidden profiles. The default profile will be highlighted in green. 233 | 234 | ![get-wtprofile](assets/get-wtprofile.png) 235 | 236 | The command displays formatted results. But there are other properties you can view. 237 | 238 | ![wtprofile properties](assets/get-wtprofile-properties.png) 239 | 240 | If you opt to view hidden profiles as well, those will be highlighted in red or at least whatever is close to red depending on your color scheme. 241 | 242 | ![hidden wtprofiles](assets/get-wtprofile-hidden.png) 243 | 244 | ### Set Default Profile 245 | 246 | Use [Set-WTDefaultProfile](docs/Set-WTDefaultProfile.md) to assign a profile from the PowerShell prompt. The easiest approach is to use `Get-WTProfile` to select a single profile and pipe that to the function. 247 | 248 | ![set-wtdefaultprofile](assets/set-wtdefaultprofile.png) 249 | 250 | ### Creating a New Profile 251 | 252 | You can use [New-WTProfile](docs/New-WTProfile.md) to create a new profile. The command parameters will set the most commonly used profile settings. You can manually adjust the profile after it has been created. 253 | 254 | ```powershell 255 | New-WTProfile -Name CMD -CommandLine cmd.exe -TabTitle Windows -CursorShape vintage -StartingDirectory "%WINDIR%" 256 | ``` 257 | 258 | Note that some values are case-sensitive. Use tab-completion wherever it is enabled for command parameters. The new profile will be inserted at the beginning of the profile list. You will need to manually edit the settings file to re-order profiles. 259 | 260 | ### Exporting Profiles 261 | 262 | For backup or testing purposes, you may want to export your custom Windows Terminal profiles with [Export-WTProfile](docs/Export-WTProfile.md). The default is to export all profiles with a commandline property. This command will not export built-in profiles like Azure Cloud Shell. You can also specify profiles to export. Wildcards are permitted. 263 | 264 | ![export-profile](assets/export-wtprofile.png) 265 | 266 | The export path must be a Json file. 267 | 268 | ### Importing Profiles 269 | 270 | Once you have an export file, you can use [Import-WTProfile](docs/Import-WTProfile.md) into your current settings. The profile name must not already exist. It is assumed the guids you are importing will be unique. Unlike using `New-WTProfile` the import process will set all profile settings that you exported. 271 | 272 | ![import-profile](assets/import-wtprofile.png) 273 | 274 | Profiles with duplicate names will be skipped. 275 | 276 | ## Windows Terminal Color Schemes 277 | 278 | `Get-WTColorScheme` is designed to show you the defined color schemes. You can select color schemes by name, including the use of wildcards, or use tab-completion. If you omit a name, the default is to get all color schemes. 279 | 280 | ![get-wtcolorscheme](assets/get-wtcolorscheme.png) 281 | 282 | The output will include a sample property formatted using the ANSI equivalent. This allows you to preview a scheme in your terminal session. Some schemes might have different definitions for a color like `red`. 283 | 284 | ![compare color schemes](assets/compare-color-scheme.png) 285 | 286 | ## Known Issues 287 | 288 | The Pester tests for this module will most likely fail when run under Pester 5.x. They are designed for Pester version 4.10.1 and need to be revised to meet the latest Pester test format. 289 | 290 | ## Future Versions 291 | 292 | If you have any suggestions for enhancements or bug reports, please use the [Issues](https://github.com/jdhitsolutions/WTToolbox/issues) section of this repository. 293 | -------------------------------------------------------------------------------- /tests/WTToolBox.Tests.ps1: -------------------------------------------------------------------------------- 1 | 2 | # Import the parent module to test 3 | 4 | if (Get-Module -Name WTToolBox) { 5 | Remove-Module -Name WTToolBox 6 | } 7 | 8 | Import-Module "$PSScriptRoot\..\WTToolBox.psd1" -Force 9 | 10 | InModuleScope WTToolBox { 11 | Describe 'ModuleStructure' { 12 | 13 | It 'Passes Test-ModuleManifest' { 14 | { Test-ModuleManifest -Path "$PSScriptRoot\..\WTToolBox.psd1" } | Should Not Throw True 15 | } 16 | 17 | It "Should export 16 functions" { 18 | ( (Get-Module WTToolbox).ExportedFunctions).count | Should Be 16 19 | } 20 | 21 | $psdata = (Get-Module WTToolBox).PrivateData.psdata 22 | It "Should have a project uri" { 23 | $psdata.projecturi | Should Match "^http" 24 | } 25 | 26 | It "Should have one or more tags" { 27 | $psdata.tags.count | Should BeGreaterThan 0 28 | } 29 | 30 | It "Should have markdown documents folder" { 31 | Get-ChildItem $psscriptroot\..\docs\*md | Should Exist 32 | } 33 | 34 | It "Should have an external help file" { 35 | $cult = (Get-Culture).name 36 | Get-ChildItem $psscriptroot\..\$cult\*-help.xml | Should Exist 37 | } 38 | 39 | It "Should have a README file" { 40 | Get-ChildItem $psscriptroot\..\README.md | Should Exist 41 | } 42 | 43 | It "Should have a License file" { 44 | Get-ChildItem $psscriptroot\..\License.* | Should Exist 45 | } 46 | } #Describe ModuleStructure 47 | 48 | Describe Install-WTRelease { 49 | 50 | Context Structure { 51 | $thiscmd = Get-Item -Path Function:Install-WTRelease 52 | 53 | It "Should use cmdletbinding" { 54 | $thiscmd.CmdletBinding | Should Be True 55 | } 56 | 57 | It "Should support -WhatIf" { 58 | $thiscmd.Parameters["WhatIf"].SwitchParameter | Should Be True 59 | } 60 | 61 | It "Should have a -Preview parameter" { 62 | $thiscmd.Parameters["Preview"].SwitchParameter | Should Be True 63 | } 64 | 65 | It "Should have help documentation" { 66 | $h = Get-Help Install-WTRelease 67 | $h.description | Should Not Be Null 68 | $h.examples | Should Not Be Null 69 | } 70 | } #context structure 71 | } 72 | Describe Backup-WTSetting { 73 | 74 | Mock Test-Path { $True } 75 | 76 | Mock -CommandName Get-Childitem -MockWith { 77 | "foo" | Out-File TestDrive:\settings.bak2.json 78 | Get-Item TestDrive:\settings.bak2.json 79 | } -ParameterFilter { $Path -eq "$env:temp\settings.bak*.json" } 80 | 81 | Mock Copy-Item {} 82 | Mock Remove-Item {} 83 | 84 | Context Structure { 85 | $thiscmd = Get-Item -Path Function:Backup-WTSetting 86 | 87 | It "Should use cmdletbinding" { 88 | $thiscmd.CmdletBinding | Should Be True 89 | } 90 | 91 | It "Should support -WhatIf" { 92 | $thiscmd.Parameters["WhatIf"].SwitchParameter | Should Be True 93 | } 94 | 95 | It "Should have help documentation" { 96 | $h = Get-Help Backup-WTSetting 97 | $h.description | Should Not Be Null 98 | $h.examples | Should Not Be Null 99 | } 100 | 101 | $p1 = (Get-Command Backup-WTSetting).parameters["Destination"].attributes | Where-Object { $_.typeid.name -match "ParameterAttribute" } 102 | It "The Destination parameter should be mandatory" { 103 | $p1.Mandatory | Should Be $True 104 | } 105 | } #context structure 106 | 107 | Context Input { 108 | 109 | } #context input 110 | 111 | Context Output { 112 | 113 | } #context output 114 | 115 | } #Describe Backup-WTSetting 116 | 117 | Describe Get-WTCurrentRelease { 118 | 119 | Context Structure { 120 | $thiscmd = Get-Item -Path Function:\Get-WTCurrentRelease 121 | 122 | It "Should use cmdletbinding" { 123 | $thiscmd.CmdletBinding | Should Be True 124 | } 125 | 126 | It "Should have a -Preview parameter" { 127 | $thiscmd.Parameters["Preview"].SwitchParameter | Should Be True 128 | } 129 | 130 | It "Should have help documentation" { 131 | $h = Get-Help Get-WTCurrentRelease 132 | $h.description | Should Not Be Null 133 | $h.examples | Should Not Be Null 134 | } 135 | 136 | } #context structure 137 | Context Input {} 138 | 139 | Context Output {} 140 | } 141 | Describe Get-WTKeyBinding { 142 | 143 | Context Structure { 144 | $thiscmd = Get-Item Function:Get-WTKeyBinding 145 | 146 | It "Should use cmdletbinding" { 147 | $thiscmd.CmdletBinding | Should Be True 148 | } 149 | 150 | It "Should have help documentation" { 151 | $h = Get-Help Get-WTKeyBinding 152 | $h.description | Should Not Be Null 153 | $h.examples | Should Not Be Null 154 | } 155 | } #context structure 156 | Context Input { 157 | 158 | $param = (Get-Command get-wtkeybinding).parameters["Format"] 159 | 160 | It "The Format parameter should have parameter validation" { 161 | $param.Attributes.TypeID.Name -contains 'ValidateSetAttribute' 162 | } 163 | It "The -Format parameter has an alias of 'out'" { 164 | $param.Aliases -contains "out" 165 | } 166 | } #context input 167 | Context Output { 168 | 169 | $global:wtSettingsPath = "Testdrive:\settings.json" 170 | 171 | $defaultContent = @" 172 | { 173 | "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", 174 | "actions": 175 | [ 176 | { "command": "closeWindow", "keys": "alt+f4" }, 177 | { "command": "toggleFullscreen", "keys": "alt+enter" }, 178 | { "command": "toggleFullscreen", "keys": "f11" }, 179 | { "command": "openNewTabDropdown", "keys": "ctrl+shift+space" }, 180 | { "command": "openSettings", "keys": "ctrl+," }, 181 | { "command": "find", "keys": "ctrl+shift+f" } 182 | ] 183 | } 184 | "@ 185 | $defaultContent | Out-File "Testdrive:\defaults.json" 186 | Mock Get-WTProcess {} 187 | Mock parsesetting { 188 | @{ 189 | Action = "closeWindow" 190 | ActionSettings = $null 191 | Keys = "alt+f4" 192 | Source = "defaults" 193 | } 194 | } 195 | 196 | Mock Get-Content { } -ParameterFilter { $Path -eq "Testdrive:\settings.json" } 197 | Mock Get-AppxPackage { 198 | @{ Name = "Microsoft.WindowsTerminal" 199 | Version = "1.4.3243.0" 200 | InstallLocation = "TestDrive:" 201 | } 202 | } -ParameterFilter { $Name -eq 'Microsoft.WindowsTerminal' } 203 | 204 | Mock Join-Path { 205 | "Testdrive:\defaults.json" 206 | } -ParameterFilter { $Path -eq "Testdrive:" -AND $childpath -eq "defaults.json" } 207 | Mock Test-Path { $True } 208 | 209 | $f = Get-WTKeyBinding 210 | It "Should call Get-AppxPackage" { 211 | Assert-MockCalled "Get-AppxPackage" -Scope Context 212 | } 213 | It "Should call Join-Path" { 214 | Assert-MockCalled "Join-Path" -Scope Context 215 | } 216 | It "Should call Get-Content" { 217 | Assert-MockCalled Get-Content -Scope Context 218 | } 219 | 220 | It "Should parse settings with a private function" { 221 | Assert-MockCalled parsesetting -Scope context 222 | } 223 | It "Should write an object to the pipeline" { 224 | $f.count | Should be 6 225 | $f[0].keys -contains "Action" | Should be True 226 | $f[0].keys -contains "ActionSettings" | Should be True 227 | $f[0].keys -contains "Source" | Should be True 228 | $f[0].keys -contains "Keys" | Should be True 229 | $f[0].psobject.typenames[0] | Should be "wtKeyBinding" 230 | } 231 | 232 | $g = Get-WTKeybinding -action "close*" 233 | It "Should get a specific action" { 234 | $g.values.count | should be 4 235 | $g.values -contains "closeWindow" 236 | } 237 | 238 | } #context output 239 | } #Describe Get-WTKeyBinding 240 | 241 | Describe Get-WTProcess { 242 | 243 | Context Structure { 244 | $thiscmd = Get-Item Function:Get-WTProcess 245 | 246 | It "Should use cmdletbinding" { 247 | $thiscmd.CmdletBinding | Should Be True 248 | } 249 | 250 | It "Should have help documentation" { 251 | $h = Get-Help Get-WTProcess 252 | $h.description | Should Not Be Null 253 | $h.examples | Should Not Be Null 254 | } 255 | } #context structure 256 | 257 | Context Output { 258 | 259 | Mock Get-CimInstance { 260 | [pscustomobject]@{ParentProcessID = 123 } 261 | } -ParameterFilter { $Classname -eq "Win32_Process" -AND $filter -eq "ProcessID=$pid" } 262 | 263 | Mock Get-CimInstance { 264 | @([pscustomobject]@{ProcessID = 300 }, [pscustomobject]@{ProcessID = 200 }) 265 | } -ParameterFilter { $Classname -eq "Win32_Process" -AND $filter -eq "ParentProcessID = 123" -AND $Property -eq "ProcessID" } 266 | 267 | Mock Get-Process { 268 | [pscustomobject]@{ProcessName = "WindowsTerminal";ID=123 } 269 | } -ParameterFilter { $ID -eq 123 } 270 | 271 | Mock Get-Process { 272 | [pscustomobject]@{ProcessName = "powershell" } 273 | } -ParameterFilter { $ID -eq 200 } 274 | 275 | Mock Get-Process { 276 | [pscustomobject]@{ProcessName = "pwsh" } 277 | } -ParameterFilter { $ID -eq 300 } 278 | 279 | $r = Get-WTProcess 280 | 281 | It "Should call Get-Ciminstance 2 times" { 282 | Assert-MockCalled Get-Ciminstance -Times 2 -Scope context 283 | } 284 | It "Should call Get-Process 3 times" { 285 | Assert-MockCalled Get-Process -Times 3 -Scope context 286 | } 287 | It "Should write 3 objects to the pipeline" { 288 | $r.count | Should be 3 289 | } 290 | 291 | It "Should write a custom object type of WTProcess" { 292 | $r[0].psobject.typenames | Should contain "WTProcess" 293 | } 294 | 295 | It "Should write a warning if not running in Windows Terminal" { 296 | 297 | Mock Get-Process { 298 | [pscustomobject]@{ProcessName = "Foo" } 299 | } -ParameterFilter { $ID -eq 123 } 300 | 301 | Get-WTProcess -WarningAction SilentlyContinue -WarningVariable w 302 | $w | Should match "\w+" 303 | } 304 | } #context output 305 | 306 | } #Describe Get-WTProcess 307 | 308 | Describe Open-WTDefault { 309 | 310 | Context Structure { 311 | $thiscmd = Get-Item Function:Open-WTDefault 312 | 313 | It "Should use cmdletbinding" { 314 | $thiscmd.CmdletBinding | Should Be True 315 | } 316 | 317 | It "Should have help documentation" { 318 | $h = Get-Help Open-WTDefault 319 | $h.description | Should Not Be Null 320 | $h.examples | Should Not Be Null 321 | } 322 | } #context structure 323 | 324 | Context Output { 325 | 326 | Mock Get-WTProcess {} 327 | It "Should throw an exception if Windows Terminal is not installed" { 328 | { Open-WTDefault } | Should Throw 329 | } 330 | It "Should write a warning if default.json is missing" { 331 | Mock Get-WTProcess { 332 | [pscustomobject]@{Name = "WindowsTerminal"; Path = "TestDrive:\windowsTerminal" } 333 | } 334 | 335 | Mock Test-Path { $False } 336 | Open-WTDefault -WarningAction SilentlyContinue -WarningVariable w 337 | $w | Should match "\w+" 338 | } 339 | It "Should open the file with Invoke-Item" { 340 | Mock Get-WTProcess { 341 | [pscustomobject]@{Name = "WindowsTerminal"; Path = "TestDrive:\windowsTerminal" } 342 | } 343 | Mock Test-Path { $True } 344 | Mock Invoke-Item {} 345 | { Open-WTDefault } | Should not Throw 346 | Assert-MockCalled Invoke-Item -Times 1 347 | } 348 | } #context output 349 | } #Describe Open-WTDefault 350 | 351 | Describe "Test-WTVersion" { 352 | Context Structure { 353 | $thiscmd = Get-Item Function:Test-WTVersion 354 | 355 | It "Should use cmdletbinding" { 356 | $thiscmd.CmdletBinding | Should Be True 357 | } 358 | 359 | It "Should have help documentation" { 360 | $h = Get-Help Test-WTVersion 361 | $h.description | Should Not Be Null 362 | $h.examples | Should Not Be Null 363 | } 364 | } 365 | 366 | Context Output { 367 | 368 | Mock Test-Path { $True } 369 | Mock Get-Content { 370 | @" 371 | { 372 | "VersionString": "1.0.0" 373 | } 374 | "@ 375 | 376 | } -ParameterFilter { $Path -eq "$home\wtver.json" } 377 | Mock ConvertTo-Json {} 378 | Mock Out-File {} 379 | 380 | It "Should throw an exception if Windows Terminal is not Installed" { 381 | Mock Get-AppXPackage {} 382 | { Test-WTVersion } | Should Throw 383 | } 384 | 385 | It "Should return a boolean result" { 386 | Mock Get-AppXPackage { @{Version = "1.0.1" } } 387 | Test-WTVersion | Should be True 388 | } 389 | } 390 | } #describe test-WTVersion 391 | 392 | Describe 'Get-WTReleaseNote' { 393 | Context Structure { 394 | 395 | $thiscmd = Get-Item Function:Get-WTReleaseNote 396 | 397 | It "Should use cmdletbinding" { 398 | $thiscmd.CmdletBinding | Should Be True 399 | } 400 | 401 | It "Should have help documentation" { 402 | $h = Get-Help Get-WTReleaseNote 403 | $h.description | Should Not Be Null 404 | $h.examples | Should Not Be Null 405 | } 406 | 407 | It "Has a parameter called AsMarkdown" { 408 | $thiscmd.parameters.keys -contains "AsMarkdown" | Should be True 409 | } 410 | 411 | It "The AsMarkdown parameter has an alias of md" { 412 | $thiscmd.parameters["AsMarkdown"].Aliases -contains "md" | Should Be True 413 | } 414 | 415 | It "Has a parameter called Online" { 416 | $thiscmd.parameters.keys -contains "Online" | Should be True 417 | } 418 | } 419 | 420 | Context Output { 421 | Mock Invoke-RestMethod { 422 | [pscustomobject]@{ 423 | prerelease = $False 424 | name = "Windows Terminal" 425 | published_at = "2020-05-05T22:25:47Z" 426 | tag_name = "v0.11.0" 427 | html_url = "http://localhost" 428 | body = "foo" 429 | bodylength = 123 430 | } 431 | } 432 | Mock Start-Process {} 433 | 434 | $r = Get-WTReleaseNote 435 | 436 | It "Should call Invoke-RestMethod" { 437 | Assert-MockCalled Invoke-RestMethod -Times 1 438 | } 439 | It "Should create a custom object" { 440 | $r | Should BeofType "PSCustomObject" 441 | $r.name | Should be "Windows Terminal" 442 | $r.Version | Should be "v0.11.0" 443 | $r.Notes | Should be "foo" 444 | $r.prerelease | Should be "false" 445 | $r.prerelease | Should BeOfType "boolean" 446 | $r.published | Should BeOfType "DateTime" 447 | } 448 | 449 | It "Should create a string object for markdown" { 450 | $md = Get-WTReleaseNote -AsMarkdown 451 | $md | Should BeofType "string" 452 | } 453 | 454 | It "Should call Start-Process to open an online link" { 455 | Get-WTReleaseNote -Online 456 | Assert-MockCalled "Start-Process" -Times 1 457 | } 458 | It "Should throw an exception if GitHub can't be reached" { 459 | Mock Invoke-RestMethod {} 460 | { Get-WTReleaseNote } | Should Throw 461 | } 462 | } 463 | 464 | } #describe Get-WTReleaseNote 465 | 466 | Describe 'Get-WTCurrent' { 467 | 468 | Context Structure { 469 | 470 | $thiscmd = Get-Item Function:Get-WTCurrent 471 | 472 | It "Should use cmdletbinding" { 473 | $thiscmd.CmdletBinding | Should Be True 474 | } 475 | 476 | It "Should have help documentation" { 477 | $h = Get-Help Get-WTCurrent 478 | $h.description | Should Not Be Null 479 | $h.examples | Should Not Be Null 480 | } 481 | 482 | It "Has no additional parameters" { 483 | $thiscmd.parameters.keys.count | Should be 11 484 | } 485 | } 486 | 487 | It "Should write a warning if there is no WT_PROFILE_ID variable" { 488 | #save the current id if exists so it can be saved 489 | $save = $env:WT_PROFILE_ID 490 | $env:WT_PROFILE_ID = $null 491 | Get-WTCurrent -WarningAction SilentlyContinue -WarningVariable w 492 | $w | Should BeOfType [System.Management.Automation.WarningRecord] 493 | 494 | $env:WT_PROFILE_ID = $save 495 | } 496 | 497 | } #describe Get-WTCurrent 498 | 499 | Describe Test-IsWTPreview { 500 | 501 | Context Structure { 502 | $thiscmd = Get-Item -Path Function:\Test-IsWTPreview 503 | 504 | It "Should use cmdletbinding" { 505 | $thiscmd.CmdletBinding | Should Be True 506 | } 507 | 508 | It "Should have help documentation" { 509 | $h = Get-Help Test-IsWTPreview 510 | $h.description | Should Not Be Null 511 | $h.examples | Should Not Be Null 512 | } 513 | } #context 514 | Context Output { 515 | Mock Get-CimInstance { 516 | [pscustomobject]@{ParentProcessID = 123 } 517 | } -ParameterFilter { $Classname -eq "Win32_Process" -AND $filter -eq "ProcessID=$pid" } 518 | Mock Get-CimInstance { 519 | [pscustomobject]@{ExecutablePath = "C:\Foo\WindowsTerminal.exe" } 520 | } -ParameterFilter { $Classname -eq "Win32_Process" -AND $filter -eq "ProcessID=123" } 521 | 522 | $t = Test-IsWTPreview 523 | It "Should call Get-CimInstance" { 524 | Assert-MockCalled Get-Ciminstance -scope context 525 | } 526 | It "Should return false if not running Windows Terminal Preview" { 527 | $t | Should Be $False 528 | } 529 | } 530 | } #describe Test-IsWTVersion 531 | 532 | } #in module scope 533 | --------------------------------------------------------------------------------