sindresorhus / open

Open stuff like URLs, files, executables. Cross-platform.
MIT License
3.18k stars 218 forks source link

Ability to pass args directly to open #183

Open jennifer-shehane opened 4 years ago

jennifer-shehane commented 4 years ago

We want the ability to pass our own flags to open, specifically the -R flag if we detect it is on darwin os. https://github.com/sindresorhus/open/issues/175

Can you allow passing along flags to open as part of the options?

const opn = require('opn')

if (os.platform() === 'darwin') {
  return opn('../foo', { args: '-R'})
}

return opn('../foo')
sindresorhus commented 4 years ago

If you only want it for macOS, why not just cal open -R directly? You don't need this package then.

jennifer-shehane commented 4 years ago

We're supporting all OS's and only want to send the -R when it's 'darwin' just because it's a nicer experience to highlight the file if we can.

Maybe the example wasn't very clear. We're actually doing the below where we patched the package to allow passing an opts.args argument then this is being used throughout our repo. But I hate having to fork our own patch for this.

const os = require('os')
const open = require('open')

module.exports = {
  open (arg, opts = {}) {
    if (os.platform() === 'darwin') {
      opts.args = '-R'
    }

    return open(arg, opts)
  },
}
sindresorhus commented 4 years ago

So what do you do on non-macOS systems? Just open the file? If so, kinda weird to have such different behavior depending on which system it is. Just a thought.

But yes, I'm open to adding an option for this. It needs a good name though.

jennifer-shehane commented 4 years ago

Yeah, it just opens the file.