Here is my use case. Often I browse directories in windows explorer and find myself in need to open the gitbash at the current directory. Now git bash comes with a nice context menu entry

enter image description here

but since I do this so often, I would like to do this with a single keyboard shortcut. I imagine the command that would have to be executed would look like

"C:\Program Files\Git\git-bash.exe" .

Is it possible assign such a keybinding to get this done using whatever tool/technique?


Here's a hotkey for this: git_bash_here.ahk; allows you to "Git Bash Here" with Ctrl+Alt+T as in Gnome.

Just grab the script (change C:\Program Files\Git\git-bash.exe if your Git is installed elsewhere) and put it in your startup folder.

| improve this answer | |
  • Used to be ctrl-alt-T for me in Gnome :) Anyway, great answer. So far I have been using the Menu-S shortcut. I just posted another answer to explain this. superuser.com/a/1152589/153117 – Chiel ten Brinke Dec 3 '16 at 20:27
  • sorry I meant to type ctrl+alt+T; updated! – Yibo Yang Dec 4 '16 at 3:31

Sometimes I use a keyboard with a special "context menu" key, which brings up the menu shown in the screenshot.

enter image description here

Pressing s after that selects and executes the "git bash here" entry.

So two keys instead of one, and you need this special key on your keyboard, but it comes for free.

| improve this answer | |

What I do is this:

  • I have a batch file titled d.bat (located in a folder on my path), the content being: start "" "%SYSTEMDRIVE%\Program Files\ConEmu\ConEmu64.exe ." (I use conemu as wrapper for git bash)
  • In windows explorer I then type Alt-D + D + <enter>. The first will select the title bar, the second will run the batch file on the current path.
| improve this answer | |

There are various ways to do this, but I'll list what I think will be the easiest way.

First lets create a shortcut.

Go to your C:\Windows\System32 folder and create a textfile with the name gb.cmd.

Edit the textfile and place the command in there that you want to use.

In your example, that would be:

"C:\Program Files\Git\git-bash.exe" %1

Save the file.

Now from your explorer, you can do the following. At the folder where you want to run git-bash, click on the address so the entire address can be typed in. Type gb . and hit enter. The gb.cmd will be run and the current path will be parsed to it.

| improve this answer | |
  • It seems I can only create folders in System32, even with admin rights. – Chiel ten Brinke Mar 18 '16 at 10:30
  • Create the file elsewhere, and copy it in. – LPChip Mar 18 '16 at 11:19
  • Done that. Now when typing gb . in the address bar, firefox starts with a google search to "gb ."... Is there a reboot required? – Chiel ten Brinke Mar 18 '16 at 11:19
  • You're typing it in the file explorer's address bar right? That shouldn't happen, unless it can't find the gb.cmd file – LPChip Mar 18 '16 at 11:21
  • Exactly so. In explorer I type Alt-D (for address bar focus) and then type gb .<enter>. Let me try a reboot. – Chiel ten Brinke Mar 18 '16 at 11:24

It works the way as suggested by LPChip. In order to open something from the file explorer address bar, you either need to give the file ending (like gb.cmd) or it needs to be an exe-file. You can put the file into any directory within the %PATH% environment variable (e.g. C:\Windows\System32).

For your example it can be easily achieved:

  1. Add the installation path of Git-Bash (e.g. C:\Program Files\Git) to the environment variable (if not already, you can try it by enter git-bash into the explorer address bar).
  2. Copy the file git-bash.exe and give a short name you want (e.g. gb.exe).
  3. Try Alt+D and enter gb in any folder within file explorer.

Unfortunately, this approach doesn't answer your question exactly. It does not execute the command you marked from the context-menu (right-click on file). As a consequence, you cannot give a file as an argument (in %1) to the application.

| improve this answer | |
  • Please read the question again carefully. Your answer does not answer the original question. "Is it possible to assign a keyboard shortcut to a certain command in windows explorer?" – DavidPostill May 7 '16 at 11:09
  • Hi DavidPostill. I know, that's what I wrote in the last sentence. At least, my answers helps the questioner to make the solution by LPChip work. – dwettstein May 8 '16 at 9:06
  • @dwettstein normally, if you're gonna give a very different second answer, just do this in a new post – Chiel ten Brinke May 18 '16 at 10:46
  • You're right, sorry. I have copied it out. – dwettstein May 18 '16 at 13:28

I have found a nice solution for your problem. With this approach you don't need the stuff I have written below previously.

You can define a hotkey for a context-menu entry in Windows Explorer by setting a & to the name in the registry shell entry (e.g. @="Edit &file with Vim"). Your hotkey is then underlined in the context-menu entry.

This allows you to execute this entry quickly by pressing Alt+f,{your hotkey} (e.g. Alt+f,f).

Update: Alt+f for opening the context-menu only works on Windows 7 (and earlier?). On Windows 10 (and I assume also 8, 8.1) you need to use Shift+F10, which is way more uncomfortable. :(

See also the answer here: Hotkey in Windows context menu

You can even use arguments (like the selected filename). You can find an example for a registry entry, which opens a file with Git Bash Vim here: https://gist.github.com/dwettstein/e5349a12852a7aadfda419e76124919c

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.