Is it possible to assign a keyboard shortcut to a certain command in windows explorer?

3

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?

Chiel ten Brinke

Posted 2016-03-18T10:06:00.830

Reputation: 1 165

Answers

2

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.

Yibo Yang

Posted 2016-03-18T10:06:00.830

Reputation: 133

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. http://superuser.com/a/1152589/153117

– Chiel ten Brinke – 2016-12-03T20:27:04.997

sorry I meant to type ctrl+alt+T; updated! – Yibo Yang – 2016-12-04T03:31:25.117

1

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.

Matty

Posted 2016-03-18T10:06:00.830

Reputation: 111

0

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.

LPChip

Posted 2016-03-18T10:06:00.830

Reputation: 42 190

It seems I can only create folders in System32, even with admin rights. – Chiel ten Brinke – 2016-03-18T10:30:44.173

Create the file elsewhere, and copy it in. – LPChip – 2016-03-18T11:19:01.193

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 – 2016-03-18T11:19:56.263

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 – 2016-03-18T11:21:10.430

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 – 2016-03-18T11:24:43.530

Reboot is not helping either. – Chiel ten Brinke – 2016-03-18T11:30:31.967

can you open a command prompt, and type echo %path% and tell me if C:\windows\system32 is mentioned somewhere in that string? This should be the case, but if not could cause for these symptoms – LPChip – 2016-03-18T13:40:58.057

Yes, it's there! – Chiel ten Brinke – 2016-03-18T13:43:15.187

0

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.

dwettstein

Posted 2016-03-18T10:06:00.830

Reputation: 23

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 – 2016-05-07T11:09:06.007

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 – 2016-05-08T09:06:55.183

@dwettstein normally, if you're gonna give a very different second answer, just do this in a new post – Chiel ten Brinke – 2016-05-18T10:46:08.290

You're right, sorry. I have copied it out. – dwettstein – 2016-05-18T13:28:33.863

0

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

dwettstein

Posted 2016-03-18T10:06:00.830

Reputation: 23

0

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.

Chiel ten Brinke

Posted 2016-03-18T10:06:00.830

Reputation: 1 165