Making Cygwin play nice with Windows filenames
I alternate operating systems every couple of months. I usually have 2 on my
computer at any given time - Windows (for compatibility & video games) and some
Linux distro. Lately, I've been using Windows for a couple of reasons, mainly
that <a href="ipython.scipy.org/">IPython</a> now works on it flawlessly, and 
that's one of my triad of crucial programs (bash, ipython, firefox). On
Windows, I spend less time hacking on the system, and more time hacking on my
code.<p>
Anyway, <a href="http://cygwin.com">cygwin</a> provides an excellent UNIX-like
environment, complete with bash shell, on Windows. However, when you want to
call Windows programs, you need to translate paths from Cygwin-Posix-Land to
Windows-Land. Cygwin provides a program, cygpath, to help you with this, but
you need to set it up to work properly. I'm posting how I set it up for 3
reasons. 1) I always forget how to do it when I have to set it up; 2) somebody
might find it useful; and 3) somebody might suggest a better way to do it.<p>
The first thing I did was to setup a script in /usr/local/bin (which I've added
to my $PATH) called wexec. This script's job is to execute an arbitrary program
with its arguments translated to Windows-land:<p>
<h2>wexec</h2>
<textarea rows="8" cols="50">#!/bin/bash
if [ "${2}" = "" ];
     then
          XPATH="";
     else
          XPATH="$(cygpath -w "${2}")";
fi
${1} $XPATH
</textarea><p>
Now, I can type "wexec notepad /cygwin.bat", and /cygwin.bat will be translated
for me into c:/cygwin/cygwin.bat, and opened up in notepad. The problem is not
completely solved yet, though. If I type the command "wexec /c/Program\
Files/Vim/vim62/gvim.exe" into bash, I get an error that it can't find
"/c/Program". For some reason, the space causes the script to hiccup. To fix
this, I softlink /usr/local/bin/vimlink to the actual vim executable.<p>
With that complete, "wexec vimlink /cygwin.bat" works as expected. However,
since it's much nicer to type "vim /cygwin.bat" than the aforementioned
command, I create one last script in /usr/local/bin:<p>
<h2>vim</h2>
<textarea rows="2" cols="50">#!/usr/bin/bash
wexec vimlink ${1} &
</textarea><p>
I then do this with every Windows program I like to use in this way 
(which fortunately is just Vim and Firefox).
The solution's not pretty, but neither is Windows' horrible command prompt, so
I'll take it. If you have an idea on how to do it easier, drop me a line at
llimllib at f2o.org.
<!--keywords: cygwin, windows, vim, computer -->
<!--time: 11-16-04 23:11-->
