File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55[ ![ npm] ( https://img.shields.io/npm/v/shelljs-plugin-open.svg?style=flat-square )] ( https://www.npmjs.com/package/shelljs-plugin-open )
66
77A [ ShellJS] ( https://github.com/shelljs/shelljs ) plugin for the ` open() ` command
8- to open a file (or URL) with its default application.
8+ to open a file (or URL) with its default application. This is largely based on
9+ [ opener] ( https://github.com/domenic/opener ) .
910
1011This is designed to imitate the ` open ` command on Mac OS X. Here's the
1112equivalent commands for other systems:
Original file line number Diff line number Diff line change 22var plugin = require ( 'shelljs/plugin' ) ;
33
44// Require whatever modules you need for your project
5- var child = require ( 'child_process ' ) ;
5+ var opener = require ( 'opener ' ) ;
66var fs = require ( 'fs' ) ;
77
88// Implement your command in a function, which accepts `options` as the
@@ -14,23 +14,17 @@ function open(options, fileName) {
1414 plugin . error ( 'Unable to locate file: ' + fileName ) ;
1515 }
1616
17- var cmd ;
18- if ( process . platform . match ( / ^ w i n / ) )
19- cmd = 'start' ;
20- else if ( process . platform . match ( / ^ l i n u x / ) )
21- cmd = 'xdg-open' ;
22- else // assume it's Mac OS X, which uses `open`
23- cmd = 'open' ;
24-
25- child . exec ( cmd + ' ' + JSON . stringify ( fileName ) ) ;
17+ var proc = opener ( fileName ) ;
18+ proc . unref ( ) ;
19+ proc . stdin . unref ( ) ;
20+ proc . stdout . unref ( ) ;
21+ proc . stderr . unref ( ) ;
2622 return '' ;
2723}
2824
2925// Register the new plugin as a ShellJS command
3026plugin . register ( 'open' , open , {
31- globStart : 1 , // Start globbing at the first non-option argument
3227 cmdOptions : { } , // There are no supported options for this command
33- wrapOutput : true , // Wrap the output in a ShellString
3428} ) ;
3529
3630// Optionally, you can export the implementation of the command like so:
Original file line number Diff line number Diff line change 3838 },
3939 "peerDependencies" : {
4040 "shelljs" : " ^0.7.3"
41+ },
42+ "dependencies" : {
43+ "opener" : " ^1.4.1"
4144 }
4245}
You can’t perform that action at this time.
0 commit comments