Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

opn

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opn - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

27

cli.js
#!/usr/bin/env node
'use strict';
var pkg = require('./package.json');
var meow = require('meow');
var opn = require('./');
function help() {
console.log([
pkg.description,
'',
var cli = meow({
help: [
'Usage',
' $ opn <file|url> [app]',
' $ opn <file|url> [app] [app arguments]',
'',

@@ -16,16 +14,7 @@ 'Example',

' $ opn http://sindresorhus.com firefox',
' $ opn http://sindresorhus.com \'google chrome\' --incognito',
' $ opn unicorn.png'
].join('\n'));
}
].join('\n')
});
if (process.argv.indexOf('--help') !== -1) {
help();
return;
}
if (process.argv.indexOf('--version') !== -1) {
console.log(pkg.version);
return;
}
opn(process.argv[2], process.argv[3]);
opn(cli.input[0], process.argv.slice(3));

@@ -16,4 +16,10 @@ 'use strict';

var cmd;
var appArgs;
var args = [];
if (Array.isArray(app)) {
appArgs = app.slice(1);
app = app[0];
}
if (process.platform === 'darwin') {

@@ -29,2 +35,7 @@ cmd = 'open';

}
if (appArgs) {
args.push('--args')
args = args.concat(appArgs);
}
} else if (process.platform === 'win32') {

@@ -42,2 +53,6 @@ cmd = 'cmd';

}
if (appArgs) {
args = args.concat(appArgs);
}
} else {

@@ -47,5 +62,8 @@ if (app) {

} else {
// http://portland.freedesktop.org/download/xdg-utils-1.1.0-rc1.tar.gz
cmd = path.join(__dirname, 'xdg-open');
}
if (appArgs) {
args = args.concat(appArgs);
}
}

@@ -66,3 +84,11 @@

cp.once('error', cb);
cp.once('close', cb);
cp.once('close', function (code) {
if (code > 0) {
cb(new Error('Exited with code ' + code));
return;
}
cb();
});
} else {

@@ -69,0 +95,0 @@ cp.unref();

{
"name": "opn",
"version": "1.0.2",
"version": "2.0.0",
"description": "A better node-open. Opens stuff like websites, files, executables. Cross-platform.",
"license": "MIT",
"repository": "sindresorhus/opn",
"bin": {
"opn": "cli.js"
},
"bin": "cli.js",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
"url": "sindresorhus.com"
},

@@ -27,10 +25,13 @@ "engines": {

"keywords": [
"cli-app",
"cli",
"bin",
"app",
"open",
"opn",
"opener",
"opens",
"launch",
"start",
"xdg-open",
"xdg",
"default",

@@ -40,4 +41,18 @@ "cmd",

"editor",
"executable"
"executable",
"exe",
"url",
"urls",
"arguments",
"args",
"spawn",
"exec",
"child",
"process",
"website",
"file"
],
"dependencies": {
"meow": "^3.1.0"
},
"devDependencies": {

@@ -44,0 +59,0 @@ "mocha": "*"

@@ -9,4 +9,7 @@ # opn

- Actively maintained
- Includes the latest [xdg-open script](http://portland.freedesktop.org/download/)
- Fixes most of the `node-open` issues
- Supports app arguments
- Safer as it uses `spawn` instead of `exec`
- Fixes most of the open `node-open` issues
- Comes with a CLI for use in your scripts
- Includes the latest [`xdg-open` script](http://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18) for Linux

@@ -16,3 +19,3 @@

```sh
```
$ npm install --save opn

@@ -27,10 +30,13 @@ ```

opn('unicorn.png');
// opens the image in the default image viewer
opn('http://sindresorhus.com');
// opens that url in the default browser
// opens the url in the default browser
opn('http://sindresorhus.com', 'firefox');
// you can also specify the app to open in
// specify the app to open in
opn('unicorn.png');
// opens the image in the default image viewer
opn('http://sindresorhus.com', ['google chrome', '--incognito']);
// specify app arguments
```

@@ -43,3 +49,3 @@

### opn(target, [app, callback])
### opn(target, [app], [callback])

@@ -51,19 +57,19 @@ #### target

The thing you want to open. Can be a url, file, or executable.
The thing you want to open. Can be a URL, file, or executable.
Opens in the default app for the file type. Eg. urls opens in your default browser.
Opens in the default app for the file type. Eg. URLs opens in your default browser.
#### app
Type: `string`
Type: `string`, `array`
Specify the app to open the `target` with.
Specify the app to open the `target` with, or an array with the app and app arguments.
The app name is platform dependent. Don't hard code it in reusable modules.
The app name is platform dependent. Don't hard code it in reusable modules. Eg. Chrome is `google chrome` on OS X, `google-chrome` on Linux and `chrome` on Windows.
#### callback(err)
#### callback(error)
Type: `function`
Executes when the opened app exits.
Called when the opened app exits.

@@ -75,18 +81,17 @@ On Windows you have to explicitly specify an app for it to be able to wait.

You can also use it as a CLI app by installing it globally:
```sh
```
$ npm install --global opn
```
```sh
```
$ opn --help
Usage
$ opn <file|url> [app]
Usage
$ opn <file|url> [app] [app arguments]
Example
$ opn http://sindresorhus.com
$ opn http://sindresorhus.com firefox
$ opn unicorn.png
Example
$ opn http://sindresorhus.com
$ opn http://sindresorhus.com firefox
$ opn http://sindresorhus.com 'google chrome' --incognito
$ opn unicorn.png
```

@@ -93,0 +98,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc