Friday, January 29, 2010

Open Cygwin/Powershell Here directory context menu entrys

For years one of the first things I installed on new windows machines was the Open Command Window Here powertoy. I'm not much of a fan of cmd and generally use cygwin for my command-line stuff, but the ability to quickly open a terminal at a particular directory was very useful.

Lately I've started to use powershell in place of cmd wherever I could. I still don't like it nearly as much as I do cygwin (probably mainly due to familiarity), but it's a lot better than cmd. I also use it in cases where cygwin doesn't play nice with windows command-line apps.


We just got new laptops at work and I'm in the process of installing all my tools on it. When I went to download the cmd here powertoy I started to wonder if there was a powershell version of the cmd here tool. Some searching lead me to a very helpful blog post showing the registry values to use for various versions of the cmd here powertoy.

The entry for powershell worked right off the bat. I copied the code into a text file, gave it a .reg extension, and double clicked it. I immediately got a "Powershell Here" entry, and it worked great.

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\powershell]
@="PowerShell Here"
[HKEY_CLASSES_ROOT\Directory\shell\powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"


In that post there was an entry for opening a cygwin shell. It worked, but the shell it opened was running in the cmd window, which for some reason behaves completely unlike all other windows. I've been using mintty for a while now (and xterm before that) to have my cygwin shells running in a real window, and I didn't want to give that up. After playing around for a while I figured out the right arguments to bash to get it to open. Here's what I came up with:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\cygwinbash]
@="Cygwin Shell Here"
[HKEY_CLASSES_ROOT\Directory\shell\cygwinbash\command]
@="c:\\cygwin\\bin\\bash.exe --login -c \"cd \\\"`cygpath -u '%L'`\\\";mintty&\""


As long as cygwin is installed at `C:\cygwin` and you have mintty installed it should work.

It's not perfect, as a cmd window will open briefly, but it's a lot better than just having "Open cmd here".

cyghere.png


Shortcut for opening cygwin or powershell windows at selected directory.

No comments:

Post a Comment

Post a Comment