Windows Terminal添加右键菜单
前言
关于Windows Terminal
的配置,后面有空再讲。
今天要说的是如何实现在当前目录打开Windows Terminal
,类似Mac
上的Go2Shell
效果。
Windows Terminal
是微软公司于西雅图开幕的Build 2019
大会上所公布的面向Windows10
的新命令行程序。用户可以通过Microsoft应用商店
安装,或从Github
下载源码自行编译安装。这一程序把目前 Windows 上的PowerShell
、CMD
以及Windows Linux子系统
(WSL
)三大环境实现了统一。
WT(Windows Terminal,后面都用WT简称)
目前自身不支持添加右键菜单的设置,但是我们可以通过注册表的方式自己添加。
解决方案
常规的操作流程,当然是先找以前有没有人干过,于是我找到了这个issues ,然后找到了这个解决方案 。经过自己的一番调试,终于成功。因此总结一下,避免后面的人踩坑。
1. 先上结论
在win10
新建一个文本文件,把下面的代码复制进去,修改文件后缀为.reg
格式,双击运行即可:
Windows Registry Editor Version 5.00
; Windows terminal
[HKEY_CLASSES_ROOT\Directory\shell\MenuWindowsTerminal]
"MUIVerb"="Windows Terminal"
"Icon"="C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminal"
[HKEY_CLASSES_ROOT\Directory\background\shell\MenuWindowsTerminal]
"MUIVerb"="Windows Terminal"
"Icon"="C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminal"
[HKEY_CLASSES_ROOT\Directory\LibraryFolder\shell\MenuWindowsTerminal]
"MUIVerb"="Windows Terminal"
"Icon"="C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminal"
[HKEY_CLASSES_ROOT\Drive\shell\MenuWindowsTerminal]
"MUIVerb"="Windows Terminal"
"Icon"="C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminal"
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\MenuWindowsTerminal]
"MUIVerb"="Windows Terminal"
"Icon"="C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminal"
; Windows Terminal SUDO
[HKEY_CLASSES_ROOT\Directory\shell\MenuWindowsTerminalSudo]
"MUIVerb"="Windows Terminal (Admin)"
"Icon"="C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminalSudo"
[HKEY_CLASSES_ROOT\Directory\background\shell\MenuWindowsTerminalSudo]
"MUIVerb"="Windows Terminal (Admin)"
"Icon"="C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminalSudo"
[HKEY_CLASSES_ROOT\Directory\LibraryFolder\shell\MenuWindowsTerminalSudo]
"MUIVerb"="Windows Terminal (Admin)"
"Icon"="C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminalSudo"
[HKEY_CLASSES_ROOT\Drive\shell\MenuWindowsTerminalSudo]
"MUIVerb"="Windows Terminal (Admin)"
"Icon"="C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminalSudo"
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\MenuWindowsTerminalSudo]
"MUIVerb"="Windows Terminal (Admin)"
"Icon"="C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminalSudo"
; Subcommands
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\CMD]
"MUIVerb"="CMD"
"ExtendedSubCommandsKey"=-
"Icon"="imageres.dll,-5323"
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\CMD\command]
@="C:\\Users\\username\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -p \"cmd\" -d ."
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\Powershell]
"MUIVerb"="Windows PowerShell"
"ExtendedSubCommandsKey"=-
"Icon"="imageres.dll,-5372"
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\Powershell\command]
@="C:\\Users\\username\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -p \"Windows PowerShell\" -d ."
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\Ubuntu]
"MUIVerb"="Ubuntu-18.04"
"ExtendedSubCommandsKey"=-
"Icon"="C:\\Program Files\\WindowsApps\\CanonicalGroupLimited.Ubuntu18.04onWindows_2020.1804.7.0_x64__79rhkp1fndgsc\\ubuntu1804.exe"
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\Ubuntu\command]
@="C:\\Users\\username\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -p \"Ubuntu-18.04\" -d ."
; Subcommands Sudo
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\CMD]
"MUIVerb"="CMD"
"HasLUAShield"=""
"Icon"="imageres.dll,-5324"
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\CMD\command]
@="cmd.exe /s /c pushd \"%V\" & start wt -p \"cmd\" -d ."
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\Powershell]
"MUIVerb"="Windows PowerShell"
"HasLUAShield"=""
"Icon"="imageres.dll,-5373"
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\Powershell\command]
@="cmd.exe /s /c pushd \"%V\" & start wt -p \"Windows PowerShell\" -d ."
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\Ubuntu]
"MUIVerb"="Ubuntu-18.04"
"HasLUAShield"=""
"Icon"="C:\\Program Files\\WindowsApps\\CanonicalGroupLimited.Ubuntu18.04onWindows_2020.1804.7.0_x64__79rhkp1fndgsc\\ubuntu1804.exe"
[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\Ubuntu\command]
@="cmd.exe /s /c pushd \"%V\" & start wt -p \"Ubuntu-18.04\" -d ."
2. README
请不要直接使用上面的代码,除非你电脑设置和我一模一样
请不要直接使用上面的代码,除非你电脑设置和我一模一样
请不要直接使用上面的代码,除非你电脑设置和我一模一样
上面的代码统称为示例代码
因为每个人的电脑环境是不一样的,所以有几处需要针对你实际的版本环境进行修改。
步骤如下:
-
请把示例代码中所有
C:\\Users\\username\\
中的username
替换为你的电脑用户名,如果你的系统在其他盘,也请修改盘符。 -
把示例代码中所有
WT
的版本号替换为你电脑中安装的WT
版本,具体操作如下:-
启用
PowerShell
, 在 C 盘根目录下执行cd '.\Program Files\WindowsApps\'
-
输入
ls
命令,找到你安装的WT
,如下面框选的部分 -
如果你的版本号与上图不同,使用你实际的版本号替换示例代码中所有的
WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe
PS: 比如你电脑里面显示的版本号是
WindowsTerminal_0.10.781.0_x64__8wekyb3d8bbwe
,那么就用这个替换示例代码中所有的WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe
-
修改
Ubuntu
版本(如果你并未安装Linux子系统
,直接把示例代码中所有Ubuntu
的部分删除,然后跳过此步骤)。如果安装的是其他 Linux 发行版,把Ubunut
替换为对应的。
-
Ubuntu 子系统的修改步骤
- 先在
C\Program Files\WindowsApps\
下找到CanonicalGroupLimited.Ubuntuxxxxx
这段东西
然后用你实际的CanonicalGroupLimited.Ubuntuxxxxx
把示例代码中的CanonicalGroupLimited.Ubuntu18.04onWindows_2020.1804.7.0_x64__79rhkp1fndgsc
全部替换掉
- 继续按照下面操作
$ cd CanonicalGroupLimited.Ubuntu18.04onWindows_2020.1804.7.0_x64__79rhkp1fndgsc
$ ls
执行结果如下:
-
请看上面框选的部分,有个
ubuntu1804.exe
,这是你实际的ubuntu
执行文件,如果你不是这个,请把示例代码中所有的ubuntu1804.exe
替换为你实际显示的 -
最后,代码中还有两处
"MUIVerb"="Ubuntu-18.04"
,请看下图,把示例代码中的Ubuntu-18.04
修改为框选的名字。
最后,保存,执行,看效果!!!