Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "open Windows terminal here" into right-click context menu #1060

Open
yanglr opened this issue May 30, 2019 · 77 comments

Comments

@yanglr
Copy link

@yanglr yanglr commented May 30, 2019

Add "open Windows terminal here" to right-click context menu?

We know that, for windows 7, by default when we click "shift + right click with mouse" when we enter into a folder without selecting anything, we can see the option "open command window here".

image

While for windows 10, by default when we click "shift + right click with mouse", we can see the option "open powershell window here".

So for Windows 10 (version later than 1903), how can we make the following three options available in right-click context menu?

  • open command window here
  • open powershell window here
  • open Windows terminal here

Looking forward to your reply, thanks a lot~

@yanglr yanglr changed the title Is there a method to add "open Windows terminal here" to right-click context menu? Is there a method to add "open Windows terminal here" into right-click context menu? May 30, 2019
@SJang1

This comment has been minimized.

Copy link

@SJang1 SJang1 commented May 30, 2019

If adding it, I think it should have one more select option in open Windows terminal here to select actually what shell to open as submenu of context menu (or like that) with the 'name' wrotted in profiles of terminal, like

  • Powershell
  • CMD
  • Ubuntu
@zadjii-msft

This comment has been minimized.

Copy link
Member

@zadjii-msft zadjii-msft commented May 30, 2019

I think this is a good feature request, and something that we'd definitely accept help from the community on.

My gut says that it'd be related to work for #689, but I don't know enough about Win32 to be sure.

@msftbot msftbot bot removed the Needs-Tag-Fix label May 30, 2019
@zadjii-msft zadjii-msft added this to Spec Needed ❓ in Specification Tracker via automation May 30, 2019
@zadjii-msft zadjii-msft added this to the Terminal Backlog milestone May 30, 2019
@miniksa

This comment has been minimized.

Copy link
Member

@miniksa miniksa commented May 30, 2019

This is probably something like this: https://www.codeproject.com/Articles/441/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens

But hopefully without re-introducing ATL into our codebase...

@factormystic

This comment has been minimized.

Copy link

@factormystic factormystic commented May 30, 2019

It's way, way easier than that to add a single command to a folder context menu. It's just a simple registry key.

For example (and then you can also add an icon, etc)

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Open Thing Here\command]
@="C:\\thing.exe \"%1\""
@ChrisGuzak

This comment has been minimized.

Copy link
Member

@ChrisGuzak ChrisGuzak commented May 30, 2019

for pacakged apps this is declared in the manifest. see this: https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-uap-filetypeassociation. I don't think this supports folders but start looking here.

@DHowett-MSFT

This comment has been minimized.

Copy link
Member

@DHowett-MSFT DHowett-MSFT commented May 30, 2019

Likely duplicate of #561, but we'll track it here.

@DHowett-MSFT DHowett-MSFT changed the title Is there a method to add "open Windows terminal here" into right-click context menu? Add "open Windows terminal here" into right-click context menu May 30, 2019
@yanglr

This comment has been minimized.

Copy link
Author

@yanglr yanglr commented May 31, 2019

@miniksa @zadjii-msft @DHowett-MSFT @factormystic @ChrisGuzak

I solved the issue now, it could be closed. Thanks a lot to all who involved into this discussion.

Step 0:

Test if two constants below works well which will be used in following other steps.

echo %USERPROFILE%

echo %LOCALAPPDATA%

If everything works well here, then these two constants can be used directly in other below steps.

Or please perform following replacements in below steps:

%USERPROFILE% → C:\Users\[userName]
%LOCALAPPDATA% → C:\Users\[userName]\AppData\Local

Here [userName] represents your user name,for instance, mine is Bruce.

Step 1:
Run below stuff in CMD:

mkdir "%USERPROFILE%\AppData\Local\terminal"

image

Step 2:
Copy the windows terminal icon to the folder %USERPROFILE%\AppData\Local\terminal, the icon can be obtained in https://github.com/yanglr/WindowsDevTools/tree/master/awosomeTerminal/icons whose file name is wt_32.ico.

Step 3:
Save follwing content as wt.reg, then run as administrator.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows terminal here"
"Icon"="%USERPROFILE%\\AppData\\Local\\terminal\\wt_32.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="%LOCALAPPDATA%\\Microsoft\\WindowsApps\\wt.exe"

To be noted, if the exe obtained after building code by yourself is wtd.exe, you need to change the above wt.exe to wtd.exe in the above registry.

Step 4:
Test
image

@SJang1

This comment has been minimized.

Copy link

@SJang1 SJang1 commented May 31, 2019

That didn't work to me (can't access to it error), and for me it was wtd.exe(didn't even work).
And I think this could be the Terminal Feature.

@yanglr

This comment has been minimized.

Copy link
Author

@yanglr yanglr commented May 31, 2019

@SJang1
I guess you used the version you bulit yourself, so need to use wtd.exe. For incoming official version to enter into Windows Store, wt.exe is the correct option here. For now, you can obtain preview version here (.7z file under https://github.com/yanglr/WindowsDevTools/tree/master/awosomeTerminal), then use wt.exe after installed. I adopted this method.

@SJang1

This comment has been minimized.

Copy link

@SJang1 SJang1 commented May 31, 2019

@yanglr I have used wtd.exe, and didn't work having error of can't access to it.. However, every end-user couldn't add to registry one-by-one.

@yanglr

This comment has been minimized.

Copy link
Author

@yanglr yanglr commented May 31, 2019

@SJang1
I guess you built the code in Debug mode, please change to Release mode, see below:
image

@SJang1

This comment has been minimized.

Copy link

@SJang1 SJang1 commented May 31, 2019

@yanglr
Already Built in Release.
image

@zadjii-msft

This comment has been minimized.

Copy link
Member

@zadjii-msft zadjii-msft commented May 31, 2019

For the record, I think we'd prefer that the terminal automatically registers this shortcut on behalf of the user.

@yanglr

This comment has been minimized.

Copy link
Author

@yanglr yanglr commented Jun 1, 2019

@zadjii-msft
Cool, great !

@yanglr yanglr closed this Jun 3, 2019
@msftbot msftbot bot added the Needs-Tag-Fix label Jun 3, 2019
@zadjii-msft zadjii-msft reopened this Jun 3, 2019
@zambelly

This comment has been minimized.

Copy link

@zambelly zambelly commented Oct 1, 2019

I use Windows Terminal with Ubuntu WSL
Is there any way to make it so that if I use "Windows terminal here", it opens in that directory I'm in, but if I just start Windows Terminal normally, it drops me into Ubuntu ~?

Making it drop me into Ubuntu home by default was relatively easy to do like this:
"commandline" : "wsl.exe ~ -d Ubuntu-18.04"
but then adding "startingDirectory": "." naturally doesn't bring the expected result for the context menu shortcut. Without the ~ in the commandline it spawns a shell in /mnt/c/Windows/System32

@ColdEvul

This comment has been minimized.

Copy link

@ColdEvul ColdEvul commented Oct 1, 2019

Here is a snippet of my settingss file:

    "defaultProfile": "{2c4de342-38b7-51cf-b940-2309a097f518}",
    "profiles":
    [
        {
            "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
            "name": "Ubuntu",
            // ... SNIPP
            //"startingDirectory" : "\\\\wsl$\\Ubuntu\\home\\andre",
            "startingDirectory" : ".",
            // ... SNIPP
        },
        // ... SNIPP
    ]

This one opens the directory your in when using Windows terminal here. But will open /mnt/c/Windows/System32 when terminal is open normally. My self have not solved this issue ether.
As you can see i also hard defined the home directory earlier before starting to use "."

@zadjii-msft

This comment has been minimized.

Copy link
Member

@zadjii-msft zadjii-msft commented Oct 1, 2019

@zambelly Not currently. That scenario would probably require #878 to be fixed to be able to support.

@Z-H-Sun

This comment has been minimized.

Copy link

@Z-H-Sun Z-H-Sun commented Oct 10, 2019

So I've got the right-click "Open Windows Terminal here" working, but I can't figure out how to get it to run as Administrator. I've tried using runas in the Registry as well as the runas verb, with no luck.

However, if I press Windows key -> type Terminal -> click "Run as administrator" I do get a Windows Terminal running as admin, so it's definitely possible.

What is the secret sauce to setup WT's environment so that it starts as administrator?

@IanKemp You may try this way by changing the value of command under the registry key runas:
cmd.exe /s /c pushd "%V" & start wt.exe

Though it is a little bit circuitous, at least this works for me.

@OmegaRogue

This comment has been minimized.

Copy link

@OmegaRogue OmegaRogue commented Oct 12, 2019

is there a way to, if there is already an instance of wt.exe running, to instead add a tab there?
And is there a way to specify which profile the new tab has?

@ktktv

This comment has been minimized.

Copy link

@ktktv ktktv commented Oct 18, 2019

Tried to add wt.exe to registry, as it described before, but I have following error:
image

Terminal is started from command line (Win+R | "wt") normally.

Same issue on my part, don't know how to fix it. Registry file as follows:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Open Windows terminal here"
"Icon"="%USERPROFILE%\\AppData\\Local\\terminal\\wt.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="%LOCALAPPDATA%\\Microsoft\\WindowsApps\\wt.exe"


[HKEY_CLASSES_ROOT\Directory\shell\wt]
@="Open Windows terminal here"
"Icon"="%USERPROFILE%\\AppData\\Local\\terminal\\wt.ico"

[HKEY_CLASSES_ROOT\Directory\shell\wt\command]
@="%LOCALAPPDATA%\\Microsoft\\WindowsApps\\wt.exe"
@ColdEvul

This comment has been minimized.

Copy link

@ColdEvul ColdEvul commented Oct 18, 2019

You need to have a absolute path and not use a variable
see: #1060 (comment)

@michael-hawker

This comment has been minimized.

Copy link

@michael-hawker michael-hawker commented Oct 22, 2019

I feel like this is the reason I'm not using Terminal more, as the way I open the command prompt is 80% from File Explorer. The rest is from Win+R+cmd+Enter, and I just learned about the wt alias, so that'll help.

When this is done, there'd be a great opportunity to expose it in in Settings as well where they have the PowerShell/CMD switch:

image

It'd be great to just have the option to select the preferred shell as a drop-down and have Terminal as an option if it's installed.

@DHowett-MSFT

This comment has been minimized.

Copy link
Member

@DHowett-MSFT DHowett-MSFT commented Oct 22, 2019

@michael-hawker what you're really looking for here is #492 😁

@Restia666Ashdoll

This comment has been minimized.

Copy link

@Restia666Ashdoll Restia666Ashdoll commented Nov 4, 2019

I automated the whole process into one bat file that you need to run as an admin.
Add Windows Terminal to context menu.zip
You still need to modify starting directory in profiles.json to "startingDiretory" : ".",

@musm

This comment has been minimized.

Copy link

@musm musm commented Nov 4, 2019

@Restia666Ashdoll that doesn't seem to get the .ico correctly

@Restia666Ashdoll

This comment has been minimized.

Copy link

@Restia666Ashdoll Restia666Ashdoll commented Nov 4, 2019

Works here though
image

@Restia666Ashdoll

This comment has been minimized.

Copy link

@Restia666Ashdoll Restia666Ashdoll commented Nov 4, 2019

Try this. Open the location of terminal.ico file. Now, go to adress bar and type "cmd".
Now, in Command Prompt enter the following command
xcopy "terminal.ico" "%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\" /b /v /y /q

@musm

This comment has been minimized.

Copy link

@musm musm commented Nov 4, 2019

Doesn't work

@Restia666Ashdoll

This comment has been minimized.

Copy link

@Restia666Ashdoll Restia666Ashdoll commented Nov 4, 2019

Just open "%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState" and manually copy the ico file then

@musm

This comment has been minimized.

Copy link

@musm musm commented Nov 4, 2019

Yeah I have done that but the problem is the registry key is not picking up the ico

@Horacehxw

This comment has been minimized.

Copy link

@Horacehxw Horacehxw commented Nov 6, 2019

I automated the whole process into one bat file that you need to run as an admin.
Add Windows Terminal to context menu.zip
You still need to modify starting directory in profiles.json to "startingDiretory" : ".",

Warning: There's a miss typing, should use "startingDirectory" : "." instead.

@guihigashi

This comment has been minimized.

Copy link

@guihigashi guihigashi commented Nov 11, 2019

what about the key HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\wt ? It doesn't need admin permission

@Restia666Ashdoll

This comment has been minimized.

Copy link

@Restia666Ashdoll Restia666Ashdoll commented Nov 11, 2019

what about the key HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\wt ? It doesn't need admin permission

It's only for current user.

@edrohler

This comment has been minimized.

Copy link

@edrohler edrohler commented Nov 15, 2019

@Restia666Ashdoll and @musm, logout and login again after copying the ico file to the LocalAppData folder. The icon will appear then.

image

@Restia666Ashdoll

This comment has been minimized.

Copy link

@Restia666Ashdoll Restia666Ashdoll commented Nov 15, 2019

@edrohler Why are you quoting me? I don't have this issue.

@Restia666Ashdoll

This comment has been minimized.

Copy link

@Restia666Ashdoll Restia666Ashdoll commented Nov 15, 2019

@Horacehxw that's only if it's the last entry.

@edrohler

This comment has been minimized.

Copy link

@edrohler edrohler commented Nov 15, 2019

@Restia666Ashdoll I quoted you thinking you might want to share the information with your batch script if anyone else asks. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Specification Tracker
  
Spec Needed ❓
You can’t perform that action at this time.