I don't like fiddling with the path on MS Windows if I can avoid it, and I avoid .bat files when I can (even though drush.bat is fairly trivial). So I set up drush under cygwin, with an alias in my .bashrc to the drush command.

The first thing I hit was that PHP wasn't able to find drush.php. I'm using a native installation of PHP, which means it expects MSDOS style filenames. I came up with a simple fix for this:

[[ $(uname -a) == CYGWIN* ]] && SCRIPT_PATH=$(cygpath -w -a -- "$SCRIPT_PATH")

inserted immediately after SCRIPT_PATH is first defined.

However: I don't have a cygwin install of PHP (assuming one exists), so this would break things if someone were using cygwin with a PHP that expected *nix style file names. I'm not sure if there's a reliable way to detect that. Nothing in the output of php -v or php -i looked ideal, though I suppose one could check the PHP config file path (from php -i or php --ini) to see with file name convention it users. And, if it's not obvious, I haven't tested this one line change on *nix, though it seems safe enough.

CommentFileSizeAuthor
#4 drush_cygwin_path_0.patch1.39 KBJaza
#2 drush_cygwin_path.patch1.38 KBJaza

Comments

greg.1.anderson’s picture

Subscribing. (Note to self: try this later, when time permits.) Note to others: there is no php in cygwin's setup.exe, so this patch would likely only hurt cygwin users who compile their own PHP from sources. I imagine that to be rare.

Jaza’s picture

Assigned: Unassigned » Jaza
Status: Active » Needs review
StatusFileSize
new1.38 KB

Gary Feldman's solution for modifying the SCRIPT_PATH fixes, for me, the issue of not being able to find drush.php. However, even after doing this, Drush still isn't able to find my Drupal installation when I'm in the root directory of a Drupal codebase.

I found that I had to modify drush_cwd() to convert cygwin's "drive emulation" paths (/cygdrive/c/dir1) into proper drive paths, albeit still with Unix slashes (c:/dir1). That got Drush fully functional on cygwin for me.

Attached patch contains Gary Feldman's solution plus mine.

Gary Feldman’s picture

I've been mounting /c for so long, I'd forgotten that it's not standard. You're right about the need to handle it, but I encourage you to check the Cygwin docs for seeing how to do the mount. Once you start using /c/drupal/... and similar, you'll forget about /cygdrive as well.

As for the fix, the regular expression doesn't look quite right. I can't think of a case that would break it, but I prefer to be precise, by insisting that the drive letter match and be exactly one letter:

$path = preg_replace('/^\/cygdrive\/([A-Za-z])/(.*)$/', '\1:/\2', $path);

Caution: I haven't even tested this to make sure it parses, let alone works. I won't be able to get to testing it today.

Jaza’s picture

StatusFileSize
new1.39 KB

Good point, Gary - no reason why the drive letter would ever be 'missing', so there's absolutely no reason for the ? operator in the regex. Updated patch attached.

I'll also have a look at how to mount drives in Cygwin - thanks for the tip!

moshe weitzman’s picture

Status: Needs review » Fixed

Committed. If this breaks, I'll coming looking for you :)

shrenster’s picture

Thanks for this, I have installed Drush against a multisite localhost Drupal installation. Jaza's patch appear's to have done the trick for cygwin.

Status: Fixed » Closed (fixed)
Issue tags: -cygwin

Automatically closed -- issue fixed for 2 weeks with no activity.