如何添加一个上下文(又名右键单击)菜单到windows资源管理器,当单击时,在当前资源管理器文件夹中打开git-bash控制台?
当前回答
在添加“使用Ruby启动命令提示符”到上下文菜单时也有类似的问题,因为它涉及到将参数与cmd补丁一起传递。遵循与上面解决方案类似的过程
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Cmd With Ruby]
@="Cmd With Ruby"
"Icon"="C:\\Windows\\System32\\cmd.exe"
[HKEY_CLASSES_ROOT\*\shell\Cmd With Ruby\command]
@="\"C:\\Windows\\System32\\cmd.exe\" \"/E:ON /K
\"C:\\Ruby25-x64\\bin\\setrbvars.cmd\"\" \"--cd=%1\"\""
[HKEY_CLASSES_ROOT\Directory\shell\bash]
@="Cmd With Ruby"
"Icon"="C:\\Windows\\System32\\cmd.exe"
[HKEY_CLASSES_ROOT\Directory\shell\bash\command]
@="\"C:\\Windows\\System32\\cmd.exe\" \"/E:ON /K
\"C:\\Ruby25-x64\\bin\\setrbvars.cmd\"\" \"--cd=%1\"\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\bash]
@="Cmd With Ruby"
"Icon"="C:\\Windows\\System32\\cmd.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\bash\command]
@="\"C:\\Windows\\System32\\cmd.exe\" \"/E:ON /K
\"C:\\Ruby25-x64\\bin\\setrbvars.cmd\"\" \"--cd=%v.\"\""
其他回答
另一种选择,但使用PowerShell脚本。
这基本上是一个PowerShell脚本,它几乎与这个答案相同(它也添加了图标)。
创建文件(addOpenGitBashHereContextMenu.ps1),粘贴下面的代码,并从PowerShell运行它。
您可能需要更改exePath以指向您的git可执行文件。 也改变contextMenuText如果你想改变上下文菜单中的文本。
$exePath = $env:USERPROFILE + '\scoop\apps\git\current\git-bash.exe'
$contextMenuText = 'Open Git Bash Here'
$regEntryName = 'git_shell'
$regPathShell = 'HKCU:\SOFTWARE\Classes\Directory\Background\shell'
$regPathContextMenu = $regPathShell + '\' + $regEntryName
$regPathCommand = $regPathContextMenu + '\command'
$user = $env:UserName
echo "Setting '$contextMenuText' context menu..."
echo " User name: '$user'"
echo " Register path: '$regPathCommand'"
echo " Executable path: '$exePath'"
# Key: shell
If (-NOT (Test-Path $regPathShell)) {
New-Item -Path $regPathShell
}
# Key: regEntryName
If (-NOT (Test-Path $regPathContextMenu)) {
New-Item -Path $regPathContextMenu -Value $contextMenuText
# Add Icon to context menu
Set-ItemProperty -Path $regPathContextMenu -Name 'Icon' -Value $exePath
}
# Key: command
If (-NOT (Test-Path $regPathCommand)) {
New-Item -Path $regPathCommand -Value $exePath
}
使用Shift + F10打开选项菜单,右键单击会出现,然后点击s到git bash这里。
什么也不做。
只要打开你的git bash终端,输入:
git update-git-for-windows
一旦更新完成,这将自动添加“Git Bash here”到您的上下文菜单。
参考这个:https://stackoverflow.com/a/65467670
除了理论和最小示例的答案外,请参阅Git .reg文件的示例(不仅是指令),该文件具有用户友好的名称、快捷键(&在用户友好的名称中)和“win-registry-snippet”存储库中的图标
下面是Registry导出(*。reg文件)Git GUI和Git Bash直接从Windows安装程序-Git GUI:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_gui]
@="Git &GUI Here"
"Icon"="C:\\Program Files\\Git\\cmd\\git-gui.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_gui\command]
@="\"C:\\Program Files\\Git\\cmd\\git-gui.exe\" \"--working-dir\" \"%v.\""
去抨击:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_shell]
@="Git Ba&sh Here"
"Icon"="C:\\Program Files\\Git\\git-bash.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_shell\command]
@="\"C:\\Program Files\\Git\\git-bash.exe\" \"--cd=%v.\""
关于*的详细信息。reg文件,请参阅微软的“如何使用.reg文件添加、修改或删除注册表子键和值”。
推荐文章
- 为什么调用git分支——unset-upstream来修复?
- Windows git“警告:LF将被CRLF取代”,这是警告尾巴向后吗?
- git中的哈希冲突
- git可以自动在空格和制表符之间切换吗?
- Git暂存文件列表
- 如何将git配置存储为存储库的一部分?
- 如何修改GitHub拉请求?
- 如何在Github和本地删除最后n次提交?
- 我如何调试git/git-shell相关的问题?
- 错误:无法使用rebase进行拉取:您有未分阶段的更改
- Git隐藏未缓存:如何把所有未分期的变化?
- 真实的恶魔
- 如何从另一个分支获得更改
- Git:权限被拒绝(publickey)致命-无法从远程存储库读取。克隆Git存储库时
- git reflog和log有什么区别?