How can I associate .sh files with Cygwin?

Jerph picture Jerph · Sep 19, 2008 · Viewed 32.5k times · Source

I'd like to run a long rsync command in Cygwin by double clicking on a .sh file in Windows. It must start in the file's containing directory (e.g. /cygdrive/c/scripts/) so that relative paths work. Anyone gotten this to work?

Note: I've just found here, a Cygwin package that manages Windows context menus (Bash Prompt Here). It might have some clues.

Answer

Jerph picture Jerph · Sep 20, 2008

Ok, I've found something that works. Associating a batch file as Vladimir suggested didn't work, but the bash arguments were key.

Short and sweet: associate with this command: "C:\cygwin\bin\bash.exe" -li "%1" %*

Long version if you don't know how:

  1. In Explorer, go to Tools/Folder Options/File Types.
  2. I already had an SH entry for Bash Script. If you don't have one, click New and enter "SH" to create one.
  3. With the SH extension selected, click Advanced.
  4. Choose the "open" action and click edit (or create the action).
  5. This is the command to use: "C:\cygwin\bin\bash.exe" -li "%1" %*. Note that without the -li, it was returing "command not found" on my scripts.

You may also want to add SH to your PATHEXT environment variable:

WinKey+Pause / Advanced / Environment Variables / System Variables / PATHEXT

Thanks for your help, guys!