Where Are The Wise Men?

Mike's Ramblings

Getting It's All Text to Play With Cygwin

| Comments

I love the FireFox plugin [It's All Text][]-- it lets me edit wiki pages, webmail, etc. in my beloved editor of Emacs and automatically refreshes the text field in FF with my new text. But I recently moved from using NTEmacs to Cygwin's version, and things simply stopped working. And it made sense -- Cygwin is just a layer on top of Windows, but it uses Unix-like paths, while It's All Text would, naturally, use Windows-style paths.

I put up with this for a few months, mostly because I didn't want to spend the cycles on figuring this out. I did spend a few, and they were all pretty much worthless. I'm not sure why -- the idea wasn't hard, but it seemed to be.

A while back I decided to put some dedicated cycles to this. I found [this comment][]from the It's All Text developer on his blog -- it didn't work , but it was a start. I took his work and built my own version. I was trying to do it with a one-script solution but seeing his some experimenting,

The following batch script should be left alone. It sets up the Cygwin environment, and then uses Cygwin's "run" command to start a bash shell, when then runs our shell script. The "%~f1" is actually the most important component here. It is a batch file command that says to give the full path of the first argument. Of course, that assumes that the first argument is a file but considering we are using this with It's All Text, we are safe with that assumption.

[shell]

@echo off
SET DISPLAY=127.0.0.1:0.0
SET CYGWIN_ROOT=c:\cygwin
SET RUN=%CYGWIN_ROOT%\bin\run -p /usr/X11R6/bin
SET PATH=.;%CYGWIN_ROOT%\bin;%CYGWIN_ROOT%\usr\X11R6\bin;%PATH%
SET XAPPLRESDIR=/usr/X11R6/lib/X11/app-defaults
SET XCMSDB=/usr/X11R6/lib/X11/Xcms.txt
SET XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
SET XNLSPATH=/usr/X11R6/lib/X11/locale

rem the %~f1 is the full path name of the argument given to the script.
%CYGWIN_ROOT%/bin/run.exe c:/cygwin/bin/bash.exe /cygdrive/h/bin/text.sh %~f1
[/shell]

The following is our shell script, which we referenced as "text.sh" above. It's much simpler -- it converts the Windows path it was given to a Unix path and then calls our editor ("emacsclient" in my case, which will load up the file in the current Emacs instance). You maybe thinking that I could have just was well as done this in the batch file above -- and, you are right, I could have ran the editor but I had to also convert the file's path first. That is really why we need two scripts -- using a shell script is the only way I could find that would let me use the cygpath command in a reliable way. Note that I used "$\*" at the path name -- that will give all the arguments, which I need because there are spaces in the full path name ("$~f1" above).

[shell]

#!/bin/sh

/usr/bin/emacsclient "`cygpath "$*"`"

[/shell]

So not easy, but it's possible. Of course, I made it a lot easier now for everyone else!