Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save futuremotiondev/dafeb72b9e7636ffd9d39af2951cd61a to your computer and use it in GitHub Desktop.

Select an option

Save futuremotiondev/dafeb72b9e7636ffd9d39af2951cd61a to your computer and use it in GitHub Desktop.

Opening Windows Terminal from the Context Menu

1. Opening WT from the Context Menu to the current directory

Note: Windows Terminal can be launched elevated or unelevated, depending on the profile you specify and its configuration in the Windows Terminal Options.

1. Open a specific profile in the currently open instance

wt -w 0 nt -p "Profile Name"

2. Open a specific profile in a new instance

wt -w new -p "Profile Name"

3. Open the default profile in the currently open instance

wt -w 0 nt

4. Open the default profile in a new instance

wt -w new

Note: If you’re opening a WSL2 Profile, the command line set in the profile will have --cd ~ at the end, which means it will always open to the home directory in Linux. In order to fix this, you need to remove the ending --cd ~ flag. See the image below for reference:

Windows Terminal Command Line Configuration

Registry Script

Here is a registry script (.reg format) to add these commands to your right-click context menu when you right click on the background of a directory or the desktop.

Note: You will have to modify the icon paths and commands to suit your specific setup.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\background\shell]

[HKEY_CLASSES_ROOT\Directory\background\shell\c56_WindowsTerminalAdmin]
@="Windows Terminal Admin"
"Icon"="\"C:\\Path\\To\\Your\\Icons\\AppCommandPrompt9.ico\""

[HKEY_CLASSES_ROOT\Directory\background\shell\c56_WindowsTerminalAdmin\command]
@=hex(2):77,00,74,00,20,00,2d,00,77,00,20,00,30,00,20,00,6e,00,74,00,20,00,2d,\
  00,70,00,20,00,22,00,50,00,6f,00,77,00,65,00,72,00,73,00,68,00,65,00,6c,00,\
  6c,00,20,00,37,00,20,00,41,00,64,00,6d,00,69,00,6e,00,22,00,00,00


[HKEY_CLASSES_ROOT\Directory\background\shell\c60_WindowsTerminalUser]
@="Windows Terminal User"
"Icon"="\"C:\\Path\\To\\Your\\Icons\\AppCommandPrompt9.ico\""

[HKEY_CLASSES_ROOT\Directory\background\shell\c60_WindowsTerminalUser\command]
@=hex(2):77,00,74,00,20,00,2d,00,77,00,20,00,30,00,20,00,6e,00,74,00,20,00,2d,\
  00,70,00,20,00,22,00,50,00,6f,00,77,00,65,00,72,00,73,00,68,00,65,00,6c,00,\
  6c,00,20,00,37,00,20,00,55,00,73,00,65,00,72,00,22,00,00,00


[HKEY_CLASSES_ROOT\Directory\background\shell\c64_WindowsTerminalUbuntu]
@="Windows Terminal Ubuntu"
"Icon"="C:\\Path\\To\\Your\\Icons\\AppUbuntu02.ico"

[HKEY_CLASSES_ROOT\Directory\background\shell\c64_WindowsTerminalUbuntu\command]
@="wt -w 0 nt -p \"WSL Bash\""

2. Launching Powershell Scripts in Windows Terminal from the Context Menu

Note: The elevated shell commands require the use of an external binary called “Elevator”, created by Beej126 on GitHub. Just place it in a folder that’s in PATH. I’ve set an environment variable to this folder named FM_BIN. So I can call "%FM_BIN%\Elevator" -elev high <command> to easily elevate the following command.

Powershell 7 - Run PS1 Unelevated

wt -d . -p "Powershell 7 User" powershell -c "pwsh.exe -noprofile -noexit -file \"%1\""
wt -w new -d . -p "Powershell 7 User" powershell -c "pwsh.exe -noprofile -noexit -file \"%1\""

Powershell 7 - Run PS1 Elevated

"%FM_BIN%\Elevator" -elev high wt pwsh.exe -noprofile -noexit -file \"%1\"
"%FM_BIN%\Elevator" -elev high wt -w new pwsh.exe -noprofile -noexit -file \"%1\"

Powershell 5 - Run PS1 Unelevated

wt -d . -p "Powershell 5 User" powershell -c "powershell.exe -nologo -noprofile -noexit -file \"%1\""
wt -w new -d . -p "Powershell 5 User" powershell -c "powershell.exe -nologo -noprofile -noexit -file \"%1\""

Powershell 5 - Run PS1 Elevated

"%FM_BIN%\Elevator" -elev high wt powershell.exe -noprofile -noexit -nologo -file \"%1\"
"%FM_BIN%\Elevator" -elev high wt -w new powershell.exe -noprofile -noexit -nologo -file \"%1\"

Registry Script

Here is another registry script to add the context menu entries for ps1 files that run them in Windows Terminal.

Note: You will have to modify the icon paths and commands to suit your specific setup.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell]

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\a16_RunPS5Elevated]
"MUIVerb"="Run Script (Admin)"
"Icon"="\"C:\\Icons\\powershell5.ico\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\a16_RunPS5Elevated\command]
@=hex(2):22,00,25,00,46,00,4d,00,5f,00,42,00,49,00,4e,00,25,00,5c,00,45,00,6c,\
  00,65,00,76,00,61,00,74,00,6f,00,72,00,22,00,20,00,2d,00,65,00,6c,00,65,00,\
  76,00,20,00,68,00,69,00,67,00,68,00,20,00,77,00,74,00,20,00,2d,00,77,00,20,\
  00,70,00,73,00,35,00,61,00,64,00,6d,00,69,00,6e,00,20,00,70,00,6f,00,77,00,\
  65,00,72,00,73,00,68,00,65,00,6c,00,6c,00,2e,00,65,00,78,00,65,00,20,00,2d,\
  00,6e,00,6f,00,70,00,72,00,6f,00,66,00,69,00,6c,00,65,00,20,00,2d,00,6e,00,\
  6f,00,65,00,78,00,69,00,74,00,20,00,2d,00,6e,00,6f,00,6c,00,6f,00,67,00,6f,\
  00,20,00,2d,00,66,00,69,00,6c,00,65,00,20,00,5c,00,22,00,25,00,31,00,5c,00,\
  22,00,00,00

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\a12_RunPS5]
"MUIVerb"="Run Script"
"Icon"="\"C:\\Icons\\powershell5.ico\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\a12_RunPS5\command]
@=hex(2):77,00,74,00,20,00,2d,00,77,00,20,00,70,00,73,00,35,00,75,00,73,00,65,\
  00,72,00,20,00,2d,00,64,00,20,00,2e,00,20,00,2d,00,70,00,20,00,22,00,50,00,\
  6f,00,77,00,65,00,72,00,73,00,68,00,65,00,6c,00,6c,00,20,00,35,00,20,00,55,\
  00,73,00,65,00,72,00,22,00,20,00,70,00,6f,00,77,00,65,00,72,00,73,00,68,00,\
  65,00,6c,00,6c,00,20,00,2d,00,63,00,20,00,22,00,70,00,6f,00,77,00,65,00,72,\
  00,73,00,68,00,65,00,6c,00,6c,00,2e,00,65,00,78,00,65,00,20,00,2d,00,6e,00,\
  6f,00,6c,00,6f,00,67,00,6f,00,20,00,2d,00,6e,00,6f,00,70,00,72,00,6f,00,66,\
  00,69,00,6c,00,65,00,20,00,2d,00,6e,00,6f,00,65,00,78,00,69,00,74,00,20,00,\
  2d,00,66,00,69,00,6c,00,65,00,20,00,5c,00,22,00,25,00,31,00,5c,00,22,00,22,\
  00,00,00

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\a08_RunPS7Elevated]
"MUIVerb"="Run Script (Admin)"
"Icon"="\"C:\\Icons\\powershell7.ico\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\a08_RunPS7Elevated\Command]
@=hex(2):22,00,25,00,46,00,4d,00,5f,00,42,00,49,00,4e,00,25,00,5c,00,45,00,6c,\
  00,65,00,76,00,61,00,74,00,6f,00,72,00,22,00,20,00,2d,00,65,00,6c,00,65,00,\
  76,00,20,00,68,00,69,00,67,00,68,00,20,00,77,00,74,00,20,00,2d,00,77,00,20,\
  00,70,00,73,00,37,00,61,00,64,00,6d,00,69,00,6e,00,20,00,70,00,77,00,73,00,\
  68,00,2e,00,65,00,78,00,65,00,20,00,2d,00,6e,00,6f,00,70,00,72,00,6f,00,66,\
  00,69,00,6c,00,65,00,20,00,2d,00,6e,00,6f,00,65,00,78,00,69,00,74,00,20,00,\
  2d,00,66,00,69,00,6c,00,65,00,20,00,5c,00,22,00,25,00,31,00,5c,00,22,00,00,\
  00

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\a04_RunPS7]
@=""
"Icon"="\"C:\\Icons\\powershell7.ico\""
"CommandFlags"=dword:00000020
"MUIVerb"="Run Script"

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\a04_RunPS7\command]
@=hex(2):77,00,74,00,20,00,2d,00,77,00,20,00,70,00,73,00,37,00,75,00,73,00,65,\
  00,72,00,20,00,2d,00,64,00,20,00,2e,00,20,00,2d,00,70,00,20,00,22,00,50,00,\
  6f,00,77,00,65,00,72,00,73,00,68,00,65,00,6c,00,6c,00,20,00,37,00,20,00,55,\
  00,73,00,65,00,72,00,22,00,20,00,70,00,6f,00,77,00,65,00,72,00,73,00,68,00,\
  65,00,6c,00,6c,00,20,00,2d,00,63,00,20,00,22,00,70,00,77,00,73,00,68,00,2e,\
  00,65,00,78,00,65,00,20,00,2d,00,6e,00,6f,00,70,00,72,00,6f,00,66,00,69,00,\
  6c,00,65,00,20,00,2d,00,6e,00,6f,00,65,00,78,00,69,00,74,00,20,00,2d,00,66,\
  00,69,00,6c,00,65,00,20,00,5c,00,22,00,25,00,31,00,5c,00,22,00,22,00,00,00


Icons

Here is a link to the icons that I’ve created and poached for use in windows terminal and my context menus:
https://drive.google.com/drive/folders/16hNYIJdgALayxQ6QkG83ebYhIzrvZ3UQ?usp=sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment