Thursday, September 6, 2007

An indispensable bash function for Cygwin

Put the following code in your .bashrc file:
function open() {
   if [ "$1" = "" ]
   then
      rundll32 url.dll,FileProtocolHandler .
   else
      rundll32 url.dll,FileProtocolHandler `cygpath -w "$1"`
   fi
}
Now you can use the open command.
  • Type open http://www.franzens.org to fire up your web browser and point it to this site.
  • Type open some_document.doc to start Microsoft Word (or Open Office) with specified document.
  • Type open some_document.txt to start notepad with specified document.
  • Type open to launch the explorer in current directory.

  • Type open //some_network_path/foo/bar to launch the explorer in specified directory.
I think you see the pattern above. I use the open command all the time and it is really useful.

2 comments:

  1. This was incredibly useful! Thank you for posting it!

    ReplyDelete
  2. Whoa, you just changed my life... why did I not find this before?

    ReplyDelete