The new Windows terminal is a huge improvement over the traditional Command Prompt and Powershell. In this post I'll explain how to create a context menu shortcut 'Open Terminal Here' which appears when you right click in File Explorer. For this we will be editing the system registry so make sure you follow these steps exactly as accidently changing something in the registry can have serious consequences.
I will assume you have installed the latest preview version of Windows Terminal from the Windows Store.
%USERPROFILE%\AppData\Local\Microsoft\WindowsApps
Hopefully this folder will contain a file called "wt.exe". This file will open up Windows Terminal. It's a good idea to check this works by double clicking on it.
You'll need to remember the path to this file for later. An easy way to get the path is by selecting the file in File Explorer and clicking "Copy path" option on the ribbon.
If you don't find the file here there are a few things you should check:
1. Try typing 'wt' into command prompt. If this doesn't open Windows Terminal, it probably hasn't been installed correctly so try reinstalling it.
2. If typing 'wt' did work then it means the file 'wt.exe' has been added to your system's PATH environment variable. Open up Windows environment variables by typing 'Environment Variables' into Windows Search and select "Edit the system environment variables" option. Then in the window that appears select "Environment Variables".
3. Then select the "Path" environment variable from the list. A list of folders should appear. Check all of these folders until you find the one containing "wt.exe", then use this path to the file.
Then within the registry editor navigate to the following folder:
HKEY_CLASSES_ROOT\Directory\Background\shell
This assumes you want to add it to all user accounts as an administrator, if just for a single user account use the following folder instead: HKEY_CURRENT_USER\Software\Classes\directory\Background\shell
Now in the left hand panel right click on "win_terminal" and select "New > Key", this time call it "command". Then select the created "command" key and double click on the "Default" key. Set the value of the key to the path you found in step 1, surrounded by speech marks. For example, on my system I used the following:
Then in the Registry Editor select the "win_terminal" folder we created. Then in the main area of the editor, right click and select "New > String Value". Give the key the name "Icon" and the value should the path to the ".ico" icon file.
You can use any .ico file you want for this or even create your own (there are lots of handy online tools that can convert a .png to .ico).
Open Windows Terminal and select "Settings" (from the drop down arrow on the top window bar). This will open the "profiles.json" in a text editor (probably notepad) which contains Windows Terminal themes and settings for different types of shells. Under "profiles" you will notice the first profile is for PowerShell, as the name is set to "Windows Powershell". Add the following line to this profile:
If you save the file and try the context menu shortcut in File Explorer again, it should now open Windows Terminal to the right working directory!
I will assume you have installed the latest preview version of Windows Terminal from the Windows Store.
Disclaimer:
Normally shells provide a command line argument when they start which you can use to specify the folder they should open to. However, Windows Terminal is still in Preview so doesn't have this yet. We will use a work-around which has a small side effect: when you open Windows Terminal by another means, (e.g. through the start menu) it will open to the Windows system folder (rather than the standard user account folder). I don't have a fix for this yet but there will definitely be one by the time Windows Terminal comes out of preview.Step 1: Find the file path to Windows Terminal
Open file explorer and enter the following into the address bar:%USERPROFILE%\AppData\Local\Microsoft\WindowsApps
Hopefully this folder will contain a file called "wt.exe". This file will open up Windows Terminal. It's a good idea to check this works by double clicking on it.
You'll need to remember the path to this file for later. An easy way to get the path is by selecting the file in File Explorer and clicking "Copy path" option on the ribbon.
If you don't find the file here there are a few things you should check:
1. Try typing 'wt' into command prompt. If this doesn't open Windows Terminal, it probably hasn't been installed correctly so try reinstalling it.
2. If typing 'wt' did work then it means the file 'wt.exe' has been added to your system's PATH environment variable. Open up Windows environment variables by typing 'Environment Variables' into Windows Search and select "Edit the system environment variables" option. Then in the window that appears select "Environment Variables".
3. Then select the "Path" environment variable from the list. A list of folders should appear. Check all of these folders until you find the one containing "wt.exe", then use this path to the file.
Step 2: Open Registry Editor
Press the Windows key (on your keyboard) and the 'R' key at the same time, to open the 'Run' app. Type in 'regedit' and press 'OK' (it will then ask for admin permissions).Then within the registry editor navigate to the following folder:
HKEY_CLASSES_ROOT\Directory\Background\shell
This assumes you want to add it to all user accounts as an administrator, if just for a single user account use the following folder instead: HKEY_CURRENT_USER\Software\Classes\directory\Background\shell
Step 3: Add the context menu item
Within the shell folder, right click and select "New > Key". Name the key something like "win_terminal". Then with the "win_terminal" key selected double click double click on the "Default" key. Enter the value "Open Terminal Here" or whatever you want the context menu item to say.Now in the left hand panel right click on "win_terminal" and select "New > Key", this time call it "command". Then select the created "command" key and double click on the "Default" key. Set the value of the key to the path you found in step 1, surrounded by speech marks. For example, on my system I used the following:
"C:\Users\James\AppData\Local\Microsoft\WindowsApps\wt.exe"
Step 4: Add an Icon
When you right click in File Explorer, it would be nice if our "Open Terminal Here" option had the Windows Terminal icon next to it. This is easy to add. First download the Windows Terminal icon as a .ico file from the official GitHub repository here. You will need to save it somewhere, where it will need to live permanently.Then in the Registry Editor select the "win_terminal" folder we created. Then in the main area of the editor, right click and select "New > String Value". Give the key the name "Icon" and the value should the path to the ".ico" icon file.
You can use any .ico file you want for this or even create your own (there are lots of handy online tools that can convert a .png to .ico).
Step 5: Set Startup Folder
You should notice the context meu item was working since the end of step 3. But it opens Windows Terminal to the default working directory, not the same directory file explorer is in. As I mentioned in the disclaimer, there is not currently a perfect solution to this since Windows Terminal doesn't have the right command line options yet. However, we can fix this another way.Open Windows Terminal and select "Settings" (from the drop down arrow on the top window bar). This will open the "profiles.json" in a text editor (probably notepad) which contains Windows Terminal themes and settings for different types of shells. Under "profiles" you will notice the first profile is for PowerShell, as the name is set to "Windows Powershell". Add the following line to this profile:
"startingDirectory" : "%__CD__%"
If you save the file and try the context menu shortcut in File Explorer again, it should now open Windows Terminal to the right working directory!
works well thanks dude
ReplyDeleteExcellent tutorial! thank you!
ReplyDelete