Skip to content

Instantly share code, notes, and snippets.

@larymao
Last active January 2, 2021 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larymao/b95ec4564956cb8c4172182573d85e44 to your computer and use it in GitHub Desktop.
Save larymao/b95ec4564956cb8c4172182573d85e44 to your computer and use it in GitHub Desktop.
Add/Remove Windows Terminal to/from Context Menu

Add/Remove Windows Terminal to/from Context Menu

Prerequisite

  • Windows 10 1903 (build 18362) or later

  • Downloads and installs wt(Windows Terminal) on your system. You can make it by following options:

How to use

Register to context menu

  1. Clones this gist to your computer.

  2. Runs script windows_terminal_here.ps1.

  3. [Optional] Opens wt, then goes to settings and sets up its starting directory as follows:

    {
      ...
      "profiles": {
        "defaults": {
          ...
          "startingDirectory": "."
          ...
        },
        ...
      },
      ...
    }
    

Remove form context menu

  1. Clones this gist to your computer.

  2. Runs script remove_windows_terminal_here.ps1.

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
exit;
}
$RegistryPathList = @(
"HKCU:\Software\Classes\Directory\shell\WindowsTerminal",
"HKCU:\Software\Classes\Directory\Background\shell\WindowsTerminal",
"HKCU:\Software\Classes\Drive\shell\WindowsTerminal",
"HKCU:\Software\Classes\LibraryFolder\Background\shell\WindowsTerminal"
)
foreach ($path in $RegistryPathList) {
Remove-Item -Path $path -Recurse
}
Write-Host -ForegroundColor Green "Windows Terminal is removed from context menu."
Write-Host -NoNewLine "`nPress any key to exit..."
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
exit;
}
# replaces icon path here with your actual location
$IconPath = "$PSScriptRoot\wt_32.ico"
$WtPath = "%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe"
$RegistryPathList = @(
"HKCU:\Software\Classes\Directory\shell\WindowsTerminal",
"HKCU:\Software\Classes\Directory\Background\shell\WindowsTerminal",
"HKCU:\Software\Classes\Drive\shell\WindowsTerminal",
"HKCU:\Software\Classes\LibraryFolder\Background\shell\WindowsTerminal"
)
foreach ($path in $RegistryPathList) {
$commandPath = "$path\command"
if (!(Test-Path $path)) {
New-Item -Path $path -Force
}
if (!(Test-Path $commandPath)) {
New-Item -Path $commandPath -Force
}
New-ItemProperty -Path $path -Name "(Default)" -Value "Windows Terminal Here" -PropertyType ExpandString -Force
New-ItemProperty -Path $path -Name "Icon" -Value $IconPath -PropertyType ExpandString -Force
New-ItemProperty -Path $commandPath -Name "(Default)" -Value $WtPath -PropertyType ExpandString -Force
}
Write-Host -ForegroundColor Green "Windows Terminal is configured to context menu."
Write-Host -NoNewLine "`nPress any key to exit..."
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment