Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I know this may be a slightly strange question, plus the fact that I'm asking it here. The reason is that whenever I ask Windows-people about this, or even regular Cygwin-users, they don't seem to understand why I need this functionality.

For those of you who haven't used "open" in the shell in Mac OS X, it works like this:

$ open somepic.jpg

$ open SomeFile.m

So it looks at the default program associated with the file, and opens it. I'd like to do the same from within Cygwin. Any ideas would be highly appreciated!

share|improve this question
add comment

3 Answers 3

up vote 14 down vote accepted
$ cygstart theFile.ext

This will open theFile.ext with the default app you have set for .ext files.

share|improve this answer
    
Exactly what I needed. Will put a: –  T.K. Aug 18 '11 at 14:01
1  
alias open='cygstart' in my .bashrc –  T.K. Aug 18 '11 at 14:01
1  
@T.K: Sweet. Feel free to drop back in again if you run into any more cygwin issues. I've been trapped in Windows land for a long time so me and Cygwin have gotten real close. We're not buddies... but we've learned to tolerate each other. ;) –  unclejamil Aug 18 '11 at 17:19
add comment

As mentioned, the best way is probably cygstart. You can add an alias to your .bashrc (or .zshrc or whatever):

alias open='cygstart'

But you can also do some things with explorer.exe. It's probably not as good as cygstart but if you run into any problems with that approach (or you need to use this with Git's bash shell rather than Cygwin) it's an option to keep in mind.

Before now I've been using the bash shell that ships with Git for Windows, and I've had

alias open='explorer.exe'

in my .bash_profile. It would open directories in Windows Explorer, and open files in the default application (by Windows' definition of "default").

It does have limitations, though. Since explorer.exe is expecting to be used at a DOS prompt (if at a command line at all), don't expect globbing to work. If, for instance, you want to open your Gemfile, Vagrantfile, Cheffile, and Rakefile all at once, and you type

open *file

You'll just get a Windows Explorer window. I don't know what logic (!?) is at work here. Most likely explorer.exe is just ignoring all the arguments, since it doesn't know what to do with multiple args.

cygstart is not very intelligent either, as it only opens the first argument when passed multiple arguments, but at least it opens a file, rather than the current directory.

share|improve this answer
add comment

For completeness, xdg-open on Linux plays much the same role on the Linux side.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.