【发布时间】:2019-12-14 15:25:47
【问题描述】:
我想通过在 Windows 文件资源管理器中单击右键打开 VSCode Remote-WSL 上的当前文件夹。 我怎样才能做到? 提前谢谢你。
【问题讨论】:
我想通过在 Windows 文件资源管理器中单击右键打开 VSCode Remote-WSL 上的当前文件夹。 我怎样才能做到? 提前谢谢你。
【问题讨论】:
要为目录添加 Windows 上下文菜单以在远程 WSL 中的 Visual Studio Code 中打开它,请将这些 Windows 注册表项添加为管理员:
reg add "HKEY_CLASSES_ROOT\Directory\shell\WSLVSCode\command" /t REG_EXPAND_SZ /d "wsl.exe code `wslpath '%1'`"
reg add "HKEY_CLASSES_ROOT\Directory\shell\WSLVSCode" /t REG_EXPAND_SZ /d "Open in WSL VSCode"
reg add "HKEY_CLASSES_ROOT\Directory\shell\WSLVSCode" /v Icon /t REG_EXPAND_SZ /d "C:\Users\User\AppData\Local\Programs\Microsoft VS Code\Code.exe"
更新图标文件的正确路径。
【讨论】:
code --remote 一起工作,因为 WSL 中的路径与 Windows 路径不同。上面的答案确实有效,但我必须在命令中使用 %V 而不是 %1(因此它也可以在 Directory/Background/shell 中工作),并且还必须在 % 之前添加反斜杠,或者将其更改为 @ 987654323@.
mshta vbscript:Execute("CreateObject(""Wscript.Shell"").Run(""wsl.exe code $(wslpath '%V')"", 0, False)(window.close)")跨度>
HKEY_CLASSES_ROOT\*\shell,后者加HKEY_CLASSES_ROOT\Directory\Background\shell,更符合默认的非wsl VSCode快捷方式。
"wsl.exe code \"`wslpath '%1'`\"" 来解决
试试这个“在 WSL 中打开文件夹”:
制作注册表文件(.reg),粘贴代码并运行:
Windows 注册表编辑器 5.00 版
;删除旧条目 [-HKEY_CLASSES_ROOT\Directory\shell\VSCode] [-HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode]
;添加右键单击文件夹的子菜单 [HKEY_CLASSES_ROOT\Directory\shell\VSCode] "MUIVerb"="Visual Studio 代码" "ExtendedSubCommandsKey"="目录\上下文菜单\VSCode" "Icon"="C:\Program Files\Microsoft VS Code\Code.exe"
;添加右键单击背景的子菜单 [HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode] "MUIVerb"="Visual Studio 代码" "ExtendedSubCommandsKey"="目录\上下文菜单\VSCode" "Icon"="C:\Program Files\Microsoft VS Code\Code.exe"
[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode]
[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell]
;设置文本和图标 [HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\open] "MUIVerb"="打开文件夹" "Icon"="C:\Program Files\Microsoft VS 代码\Code.exe"
[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\openwsl] "MUIVerb"="在 WSL 中打开文件夹" "Icon"="C:\Program Files\Microsoft VS 代码\Code.exe"
;设置命令 [HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\open\command] @=""C:\Program Files\Microsoft VS Code\Code.exe" "%V""
[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\openwsl\command] @="wsl.exe --cd "%V" 代码。" ;这将打开当前文件夹 WSL 端,然后从那里运行代码
结果:Sample image
来自:https://gist.github.com/mbartelsm/be2a8ea761e5358cd04e3777d107b186#file-vscode_context-reg
这适用于“使用 WSL 中的代码打开”(在 WSL 中打开文件):
制作注册表文件(.reg),粘贴代码并运行:
Windows 注册表编辑器 5.00 版
[HKEY_CLASSES_ROOT*\shell\VSCodeWsl] @="使用 WSL 中的代码打开(&&)" "Icon"="C:\Program Files\Microsoft VS Code\Code.exe"
[HKEY_CLASSES_ROOT*\shell\VSCodeWsl\command] @="wsl.exe 代码 "$(wslpath '%1')""
【讨论】: