-1

I've Windows Terminal (Preview) pinned to taskbar which I launch using win+t. I'm trying to achieve a similar functionality to alt+f+r inside a directory in file explorer which opens powershell in the current directory. I've tried setting startDirectory in profiles.json to null, "." and "~" but none work.

I think it's not possible for the terminal to know which directory I'm currently in if I launch it from the taskbar, if so, is there a way to launch it through file explorer (preferably using keyboard shortcuts only) and have the terminal shells open in the current directory?

3
  • When in Explorer you type in the address bar wt.exe and Enter, does it launch Windows Terminal inside the current folder?
    – harrymc
    Commented Jan 30, 2020 at 17:37
  • @harrymc yes it does, but only when startingDirectory is set to ".", is there a shortcut for this? don't want to type in wt.exe. Perhaps any registry tweaks?
    – Chase
    Commented Jan 31, 2020 at 5:17
  • I'm not using Windows Terminal, but my answer should work.
    – harrymc
    Commented Jan 31, 2020 at 9:13

4 Answers 4

-1

You may use the free key-remapping product AutoHotkey.

Here is a script that will start the Windows Terminal on the current folder in Explorer when F12 is clicked.

#IfWinActive ahk_class CabinetWClass
~F12::
    ControlGetText, _Path, toolbarwindow322, ahk_class CabinetWClass
    StringReplace, _Path, _Path,% "Address: ",% ""
    Run "wt.exe", %_Path%

After installing AutoHotKey, put the above text in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group at
C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

For choosing another hotkey than F12, see AutoHotkey List of Keys.


You could also add this to the shell context menu by this method:

  1. Start regedit and navigate to the key HKEY_CLASSES_ROOT\Directory\Background\shell
  2. Right-click shell and select New > Key, naming it perhaps Windows Terminal
  3. Right-click the new Windows Terminal key and select again New > Key, naming it command
  4. In the new command key folder, double-click the (Default) key on the right and set it to the path to the executable file and hit OK.

You will probably not be able to set the command to \path\wt.exe "%V", because Windows Terminal does not accept parameters, so you will need to use a batch file, \path\script.bat "%V", where the batch file will look like:

cd "%1"
start "" \path\wt.exe
6
  • 1
    That's great and all, and I already knew about AHK but I'm looking for an answer that doesn't require third party tools.
    – Chase
    Commented Jan 31, 2020 at 9:39
  • Is that a reason for the downvote? You didn't state that in your post. The only other way is to do it yourself by typing "Ctrl+L wt Enter".
    – harrymc
    Commented Jan 31, 2020 at 9:42
  • I'm not the one who downvoted. Don't have enough rep yet for downvote. You're correct I didn't mention that explicitly but I was really lookin for, perhaps, even a registry tweak to add wt.exe in the right click menu.
    – Chase
    Commented Jan 31, 2020 at 9:46
  • Some downvotes are incomprehensible. I added a second method using the registry that you will need to try, since I don't have Windows Terminal.
    – harrymc
    Commented Jan 31, 2020 at 10:15
  • Thanks, that works! I should mention, you do not need a .bat file, just put \path\to\wt.exe in command and put "." in startingDirectory in profiles.json of the terminal.
    – Chase
    Commented Jan 31, 2020 at 11:44
0

You can add PowerShell to the Quick Access toolbar, and use e.g. Alt + 3. The number depends on the location of the command on that toolbar.

0

TL;DR: This answer will enable you to use Shift+Context Menu Key, t (or Shift+F10, t) on either the folder background, a selected file, or a selected folder, and it will open Windows Terminal in the path to the open folder, the path to the selected file, or the path to the selected folder. It also has options for opening an elevated version.

Below is a link to an article about adding "Open Windows Terminal Command Prompt" to the context menu in Explorer, which includes a shortcut to the elevated version and also keyboard shortcuts that can be accessed using Shift+Context Menu Key (or Shift+F10 if you don't have a context menu key).

NOTE: If there is more than one menu item assigned to 't', then you will have to press 't' until the option you want is selected, and then press Enter. You can also change 't' to whatever you want by moving the & in the menu text or even add characters to the string to make it unique so you can avoid having to press Enter.

https://dkcool.tailnet.net/2020/07/add-open-windows-terminal-command-prompt-to-the-explorer-context-menu-in-windows-10/

If you want it to open powershell and not the command prompt, then you can modify the registry values in the article and change "Command Prompt" in the command key default value to "Windows Powershell". If you want it to open an Ubuntu shell, change "Command Prompt" to the specific name that you have installed, like "Ubuntu-18.04". See the Microsoft link below for more command line options.

WT.exe command line arguments: https://docs.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows

Similar article about adding Open Admin Command Prompt to the context menu in Explorer: https://dkcool.tailnet.net/2019/05/add-open-admin-command-prompt-to-the-explorer-context-menu-in-windows-10/

-1

Here is my AHK recipe. If you hit F12 in a File Explorer window, it sends Alt+D, followed by Ctrl+C to get the current path. Then, it runs the "wt.exe -d [current path]" command and clears the clipboard:

#IfWinActive ahk_class CabinetWClass
~F12::
    send, !d
    Sleep, 100
    send, ^c
    Sleep, 100
    command = wt.exe -d  "%Clipboard%"    
    Clipboard := ""
    Run, %command%
Return

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .