Skip to main content

Adding Context Menu Item for Windows Terminal To File Explorer

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.

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!

All done!

Thanks for reading, I hope this was useful to you. Please leave questions or comments below.

Comments

Post a Comment

Popular posts from this blog

Terminals in Sublime Text 3

If you need a quick answer on how to create terminals in Sublime Text 3, watch the following video, or read the instructions below it. How to set up Terminals in Sublime Text 3 Open Sublime Text. Open the Command Palette with Crtl+Shift+P Type  'Package Control: Install Package' until the option appears and select it [You'll need to install package control if you are using it for the first time] Type 'Terminus' and select it. Now the package Terminus will install. Wait for this to complete. Then restart Sublime Text. Next we will add Commands to the Command Palette. So you can open terminals using Crtl+Shift+P then typing a command. To do this open the Command Palette (Ctrl+Shift+P) and type 'Terminus: Command Palette' and open it. You'll be greeted by a split view. Basically there are settings defined in the code on the left panel and you can override them or add your own by typing code in the right panel. Copy ...

Generating a MSI Installer for a WPF Application

This post serves as a tutorial for creating a MSI installer for your WPF Applications in Visual Studio. For this we use WiX (recommended by Microsoft). Prerequisites I assume you already have a Visual Studio solution containing a WPF Project. And I assume you have some experience with Visual Studio and XML. You do not need any prior knowledge of WiX. Step 1: Install Wix We are going to need WiX to generate our MSI. If you don't already have Wix installed, go ahead and download it from here . You'll be redirected to the relevant GitHub releases page where you can download the .exe file to install WiX.

Fill your GitHub activity heatmap with the image of your choice

Taking 12 months to upload a 52x7 pixel image, through thousands of git commits, ... that's completely reasonable right?