getting drush 3 to work with cygwin

in

Being one to avoid religious arguments, I tend to not get too upset by some of the hoops Windows can put me through - but I will admit that Unix-based development usually has fewer mysteries to it. I've got a Mac and a Linux server, so why do I put up with Windows at all? Short answer is that as a professional Drupal developer, I can't imagine life without the phpED IDE. Simple as that. I hadn't used an IDE for years, but fell in love with phpED after Peter Lindstrom walked me through it a few Drupalcons ago. I've tried Eclipse and some other debuggers, but nothing comes close for productivity for me.

But there's still that Windows part, and as masochistic as I am at some times, there's now way I'm going to working the cmd window. Fortunately, we have cygwin, a pretty decent Unix shell that runs under Windows and allows me to use Unix commands and familiar tools. I use it in conjunction with the LAMP stack Xampp to have a pretty nice local dev environment. However, it has one foot in each world, and took me a little work to figure out how to get drush to work with it.

Actually, I'd been using drush for some time on my local, and only started having problems when version 3 was released. One of the new features it introduced is site aliases, which allow you to set up a list of shortcuts to the configuration for a particular local or remote site. Before that, I'd been using a mishmash of batch scripts to run the right config for the different sites I work on, or had to create drushrc files for each site and reference them on the command line.

I read Morten's excellent tutorial on drush configuration for the Mac and had it running there is a few minutes. But I just couldn't get it to work under cygwin on my PC.

In my .bashrc, I added this alias to point to drush:

alias drush="/cygdrive/p/drush/drush"

I also made a symlink from my Xampp php executible to /usr/local/bin/php. Drush worked fine as long as I had a drushrc.php file for a site, or use -r and -l args on the command line to point to my site.

So far so good. But when I tried "drush sa" to list my site aliases, I would get strange errors. Greg Anderson suggested I try setting a global site-alias option in my master drushrc.php file (the one in my drush directory), to point to my ~/.drush directory, where I have my aliases.drushrc.php file. So I tried

$options['alias-path'] = '/home/phil/.drush';

but that didn't work. After a lot of experimenting, it turns out this is the answer:

$options['alias-path'] = 'c:\\cygwin\\home\\phil\\.drush';

It wanted a Windows-style path, even though the Unix-style paths work fine in places like settings.php. The drushrc appears to being evaluated in Windowsland, but things get more Unixy once we are in Drupal. Dangit, why does life have to be so difficult sometimes?

One more thing - when I run this on my PC, I see the line #!/usr/bin/env php whenever I run drush. Taking a clue from Solomon, I edited drush.php and removed it. Works fine without it, and no annoying extra output.

I'm delighted now, and love the extra power of site aliases (which even have powers of inheritence). If you haven't used them yet, by all means give them a try. Here's a brief introduction article.

A bit of head scratching, but a big payoff, and I know a few more Windows/cygwin gotchas. Funny how a geek can invest hours in something that can save a few minutes. But when you're deep in the middle of coding, a few seconds delay can make you lose an entire train of though sometimes, so I don't regret it. Or as my hero Larry Wall put it, "The three chief virtues of a programmer are: Laziness, Impatience and Hubris."
 

Comments

thanks for this, Phil.

Good article... as a Drupal developer and power user I sometimes ask myself why I'm still still in Windows land myself. I too use Nusphere PHPEd -- every other PHP editor I've tried (including Eclipse, though I haven't tried Zend.. have you?) pales in comparison. The other reason I'm on Windows is for the incredibly powerful and flexible media program J R Media Center, to which nothing even compares (certainly not iTunes). Anyhow, I ran Drush previously using the gnuwin tools as was popularized after the drush 2.0 release. But certain things didn't work and other things were painfully slow. So I basically left Drush. But with the release of Drush 3.0 and with my firm pushing for me to use Drush regularly, I'm looking at it again. I swear I'm about ready to turn my PC into a hackintosh and switch to Zend, and run my media player in a virtual windows machine, just to use Drush in a painless way. But before I go that far, I want to investigate using cygwin instead of gnuwin, as cygwin seems to be the more popular unix layer for windows drush users these days, according to my google searches. My concern is about speed. I've heard stories about Drush on cygwin being really slow, like a minute to execute a command -- which is about equivalent to my gnuwin experience. Can you comment? Also, has everything else worked for you, ie. what parts of Drush are not working for you? Any thoughts are much appreciated. Shiraz shiraz@theshiraz.net

most of it works

My biggest problem is I can't run pm-update on sites with Subversion used, because it first moves everything from a module directory to a backup directory, including the .svn files! Yes, cygwin is a bit slow; it also does weird things with file ownerships and permissions some times.

Better not to do a hackintosh number; get a used Mac Mini and run native. You'll still want your Windows box for testing sites, and a "real" mac is going to take less twiddling.

thanks.

Thanks for your response, Phil. I decided against the hackintosh idea. And rather than getting a Mac Mini, it would be simpler for me to buy a new windows laptop, one with a CPU with hardware virtualization, which I've heard makes running a virtual box almost as fast as using an original.

Until then, how's Cygwin working out for you? Is it *unbearably* slow, ie. slow to the point that you don't bother with Drush? And most of our projects are in SVN (moving to GIT but still lots of subversion reps), so I'm glad for that heads up. Is that still an issue, and still your biggest issue?

Thanks,

Shiraz

slow

Yes, speed, and the svn issue. I use drush a lot, though, for grabbing modules, inspecting/setting vars, and clearing caches. It's faster than my local server. I think a lot of the problem with cygwin is the difficulty in mapping a Unix style file system to Windows. I've had issues involving file permissions that made some apps impossible to run.