File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,3 +58,10 @@ shell.open('file.txt'); // the plugin is now available!
5858 - Windows
5959
6060This is only supported for Node v4+
61+
62+ ## Writing plugins
63+
64+ If you're interested in taking a look at the current state of the plugin API,
65+ take a look at [ index.js] ( index.js ) . This has helpful comments explaining the
66+ necessary boilerplate for writing a plugin. For an example usage of the plugin,
67+ take a look at [ test/test.js] ( test/test.js ) .
Original file line number Diff line number Diff line change 1+ // This exposes the plugin utilities
12var plugin = require ( 'shelljs/src/common' ) ;
3+
4+ // Require whatever modules you need for your project
25var child = require ( 'child_process' ) ;
36var shell = require ( 'shelljs' ) ;
47var fs = require ( 'fs' ) ;
58
6- //@
7- //@ ### open([options,] file [, file ...])
8- //@ ### open([options,] file_array)
9- //@ Examples:
10- //@
11- //@ ```javascript
12- //@ open('file.jpg');
13- //@ ```
14- //@
15- //@ Opens files with their default application
9+ // Implement your command in a function, which takes an options string as the
10+ // first parameter
1611function open ( options , fileName ) {
12+ // Use the plugin utils to parse the options to only those options that are
13+ // available (in this case, there are no available options
1714 options = plugin . parseOptions ( options , {
1815 } ) ;
1916
@@ -36,6 +33,8 @@ function open(options, fileName) {
3633 return new shell . ShellString ( '' , '' , 0 ) ;
3734}
3835
36+ // Register the new plugin as a ShellJS command
3937plugin . register ( 'open' , open , { globStart : 1 } ) ;
4038
39+ // Optionally, you can export the implementation of the command like so:
4140exports . open = open ;
Original file line number Diff line number Diff line change 1- /* globals describe, it, before, afterEach */
1+ /* globals describe, it */
2+
3+ // Steps for using a plugin:
4+ // First, you must load in ShellJS:
25var shell = require ( 'shelljs' ) ;
3- var pluginOpen = require ( '..' ) ; // load plugin
6+ // After that, you can load the plugin:
7+ var pluginOpen = require ( '..' ) ;
8+ /*
9+ * You can load a plugin with either of the following syntaxes:
10+ * `require('shelljs-plugin-open');` or
11+ * `var pluginOpen = require('shelljs-plugin-open');`
12+ */
13+
14+ // Now, require whichever other modules you want to require:
415require ( 'should' ) ;
516
617// override console.error() to cover up common.error() calls
You can’t perform that action at this time.
0 commit comments