如何添加一个上下文(又名右键单击)菜单到windows资源管理器,当单击时,在当前资源管理器文件夹中打开git-bash控制台?


当前回答

另一种选择,但使用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
}

其他回答

@Shaswat Rungta说:“我认为问题更多的是如何在安装结束后添加它。”

在我的PC(Windows 7)上,我认为在安装Visual Studio 2017后,“Git Bash here”命令消失了。

我通过下载并重新安装Git来解决这个问题。 注意:“安装Git for Windows时,默认情况下上下文菜单选项不是‘开启’的。你必须在安装过程中选择它们。”——@nbushnell (我这样做了)

我也有类似的问题,我这样做了。

第一步:在开始菜单中输入“regedit”

步骤2:运行注册表编辑器

步骤3:导航到HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell。如果您没有shell密钥,请创建一个。

第四步:右键单击“shell”,选择“New > Key”。命名键“Bash”

第五步:修改值并将其设置为“open in Bash”这是在右键单击中出现的文本。

步骤6:在Bash下创建一个新密钥,命名为command。将该键的值设置为git-bash.exe路径。

关闭注册表编辑器。

你现在应该可以在资源管理器的右键菜单中看到这个选项

PS Git Bash默认选择当前目录。

编辑:如果你想要一个点击的方法,检查下面的Ozesh的解决方案

将gitpath添加到Environment-path变量(例如C:\Program Files\Git\ cmd),通过该变量,您可以使用命令行从任何文件夹访问git。

另一种选择,但使用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
}

当你在“https://git-scm.com/downloads”中安装git-scm时,取消位于安装窗口最底部的“只显示新选项”

一定要检查

Windows资源管理器集成 Git Bash在这里 Git GUI在这里

单击Next,您就可以开始了!