How to run any windows program from cygwin, still using cygwin-style path

In my previous post I posted a script useful for running kdiff3 for windows correctly from within cygwin. Here’s a more general version that can be used for any windows program. Save the following as ~/cygwinify.sh (or whatever you like):


#!/usr/bin/bash
RESULT=""
for arg
do
if [[ "" != "$arg" ]] && [[ -e $arg ]];
then
OUT=`cygpath -wa $arg`
else
if [[ $arg == -* ]];
then
OUT=$arg
else
OUT="'$arg'"
fi
fi
RESULT=$RESULT$OUT" "
done
echo "$RESULT"

The script tries to find any file or directory names in your command line arguments, and converts them to absolute, windows-style path names using cygpath -wa. You can then run something like:

explorer `~/cygwinify.sh /tmp`

And it will open Windows Explorer in the correct folder.

Also, the script to run kdiff3 becomes (just replace the path to the executable with your own):


#!/usr/bin/bash
"/cygdrive/d/Program Files (x86)/KDiff3/kdiff3.exe" `~/cygwinify.sh "$@"`

About these ads

2 thoughts on “How to run any windows program from cygwin, still using cygwin-style path

  1. Pingback: How to use kdiff3 as a difftool / mergetool with cygwin git « Enough Blogging!

  2. I use a similar script but I avoid the backticks by including the running of the command in the script, so it’s like this:

    cygwinify.sh some/windows/prog.exe /home/whatever /tmp/foo

    I think it’s easier to type this way. You do lose tab-completion of the exe name if you don’t type it first, although that might be fixable in bash somehow.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s