[go: up one dir, main page]

Menu

#121 "open" utility

1.0
closed
nobody
None
2017-02-05
2015-01-11
morous
No

On Mac OS X, there is a command line utility open(1) (https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/open.1.html), which opens given files (or directories) as they would be clicked in system user interface, i.e. they are open in the default application for opening that particular file type.

I hacked a very trivial variant of it for Windows some time ago as I found it immensely useful for usage within MSYS2 (or any shell) environment. Perhaps it would be worth of adding it (or some enhanced variant of this) into MSYS2 if other people find it useful too.

The utility source is attached. To build it I normally use CMake, but that's probably unsuitable here as MSYS2 uses autotools. But manual build may be done with this one-liner so adding it into MSYS2 should be trivial.

$ gcc -Wall -municode -DUNICODE -D_UNICODE -DWIN32_LEAN_AND_MEAN -lshell32 open.c -o open.exe

So adding it anywhere into MSYS2 should be likely trivial.

The usage is as simple as:

$ open PATH [PATH...]

If there is any interest in adding it, I am open to add some formal enhancements like man page and/or --help option support etc.

1 Attachments

Discussion

  • Ray Donnelly

    Ray Donnelly - 2015-01-11

    Sounds good. I think adding it to the MSYS2 filesystem package would be appropriate. No need to setup a complex build system, calling gcc from PKGBUILD would be fine IMHO, but if you want to go to town on docs and translation then a build system might become appropriate. Personally I don't think documentation is essential for something as self describing as open. I've not checked but how are you handling mime types? Do we want to have our own wrapper to mime types so that MSYS2-installed stuff gets preference?

     
    • Angelo Graziosi

      Angelo Graziosi - 2015-01-11

      But MSYS has already this application! It is called "start" (in an old ticked I asked for cygstart which is in Cygwin, and Alexey clarified...):

      $ which start
      /usr/bin/start
      

      with an 'alias' (in shell initialization files) I have solved your issue:

      alias open='start'
      
      
      open /POSIX_PATH/foo.pdf
      

      opens foo.pdf with the default PDF reader on Windows. In the same manner

      open /POSIX_PATH/foo.jpg     (Picasa viewer)
      open /POSIX_PATH/foo.MOV     (WMP)
      ...
      

      Ciao,
      Angelo.

       
      • morous

        morous - 2015-01-11

        Ohh. I missed "start" completely. Ok, consider the ticket irrelevant then.

         
      • Angelo Graziosi

        Angelo Graziosi - 2015-01-11

        BTW, I often use it to install Windows applications,

        open [...]/picasa39-setup.exe
        open [...]/LibreOffice_4.3.5_Win_x86.msi
        

        (exactly as I do on OSX with .dmg applications : 'open LibreOffice_4.3.5[...].dmg')

        Also:

        open [...]/foo.html   (Chrome)
        open [...]/foo.tar.xz (7zip)
        ...
        

        On GNU/Linux there is an application (now I don't remember the name...) similar to OSX-open, [cyg]start. So with a similar alias I did the same on GNU/Linux...

        Ciao,
        Angelo.

         
    • morous

      morous - 2015-01-11

      @Ray: I do not. I leave the hard work on SHELL32.DLL

       
  • David Macek

    David Macek - 2017-02-05
    • status: open --> closed