Skip to content

Commit

Permalink
Add --background flag for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 7, 2019
1 parent 555f0ae commit 8688742
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
22 changes: 15 additions & 7 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const opn = require('opn');
const open = require('open');
const getStdin = require('get-stdin');
const tempWrite = require('temp-write');
const fileType = require('file-type');

const cli = meow(`
Usage
$ opn <file|url> [--wait] [-- <app> [args]]
$ cat <file> | opn [--wait] [--ext] [-- <app> [args]]
$ opn <file|url> [--wait] [--background] [-- <app> [args]]
$ cat <file> | opn [--ext] [--wait] [--background] [-- <app> [args]]
Options
--wait Wait for the app to exit
--ext File extension for when stdin file type can't be detected
--wait Wait for the app to exit
--background Do not bring the app to the foreground (macOS only)
--ext File extension for when stdin file type can't be detected
Examples
$ opn https://sindresorhus.com
Expand All @@ -27,6 +28,13 @@ const cli = meow(`
wait: {
type: 'boolean',
default: false
},
background: {
type: 'boolean',
default: false
},
ext: {
type: 'string'
}
}
});
Expand All @@ -41,12 +49,12 @@ if (!input && process.stdin.isTTY) {
}

if (input) {
opn(input, cli.flags);
open(input, cli.flags);
} else {
(async () => {
const stdin = await getStdin.buffer();
const type = fileType(stdin);
const ext = cli.flags.ext || (type && type.ext) || 'txt';
opn(tempWrite.sync(stdin, `opn.${ext}`), cli.flags);
open(tempWrite.sync(stdin, `opn.${ext}`), cli.flags);
})();
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "opn-cli",
"version": "4.0.0",
"description": "A better node-open. Opens stuff like websites, files, executables. Cross-platform.",
"description": "Open stuff like URLs, files, executables. Cross-platform.",
"license": "MIT",
"repository": "sindresorhus/opn-cli",
"author": {
Expand Down Expand Up @@ -51,15 +51,15 @@
"file"
],
"dependencies": {
"file-type": "^10.4.0",
"file-type": "^10.10.0",
"get-stdin": "^6.0.0",
"meow": "^5.0.0",
"opn": "^5.4.0",
"open": "^6.1.0",
"temp-write": "^3.4.0"
},
"devDependencies": {
"ava": "^0.25.0",
"ava": "^1.4.1",
"execa": "^1.0.0",
"xo": "^0.23.0"
"xo": "^0.24.0"
}
}
13 changes: 7 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# opn-cli [![Build Status](https://travis-ci.org/sindresorhus/opn-cli.svg?branch=master)](https://travis-ci.org/sindresorhus/opn-cli)

> A better [node-open](https://github.com/pwnall/node-open). Opens stuff like websites, files, executables. Cross-platform.
> Open stuff like URLs, files, executables. Cross-platform.

## Install
Expand All @@ -16,12 +16,13 @@ $ npm install --global opn-cli
$ opn --help
Usage
$ opn <file|url> [--wait] [-- <app> [args]]
$ cat <file> | opn [--wait] [--ext] [-- <app> [args]]
$ opn <file|url> [--wait] [--background] [-- <app> [args]]
$ cat <file> | opn [--ext] [--wait] [--background] [-- <app> [args]]
Options
--wait Wait for the app to exit
--ext File extension for when stdin file type can't be detected
--wait Wait for the app to exit
--background Do not bring the app to the foreground (macOS only)
--ext File extension for when stdin file type can't be detected
Examples
$ opn https://sindresorhus.com
Expand All @@ -37,7 +38,7 @@ The [following file types](https://github.com/sindresorhus/file-type#supported-f

## Related

- [opn](https://github.com/sindresorhus/opn) - API for this module
- [open](https://github.com/sindresorhus/open) - API for this module


## License
Expand Down

0 comments on commit 8688742

Please sign in to comment.