GeezerVison is showing github.com — tools: add bash completion for node · nodejs/node@a22485d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +11Lines changed: 11 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -52,6 +52,17 @@ If this flag is passed, the behavior can still be set to not abort through | 52 | 52 | [`process.setUncaughtExceptionCaptureCallback()`][] (and through usage of the | 53 | 53 | `domain` module that uses it). | 54 | 54 |
| | 55 | +### `--completion-bash` | | 56 | +<!-- YAML | | 57 | +added: REPLACEME | | 58 | +--> | | 59 | + | | 60 | +Print source-able bash completion script for Node.js. | | 61 | +```console | | 62 | +$ node --completion-bash > node_bash_completion | | 63 | +$ source node_bash_completion | | 64 | +``` | | 65 | + | 55 | 66 | ### `--enable-fips` | 56 | 67 | <!-- YAML | 57 | 68 | added: v6.0.0 | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,6 +75,9 @@ the next argument will be used as a script filename. | 75 | 75 | .It Fl -abort-on-uncaught-exception | 76 | 76 | Aborting instead of exiting causes a core file to be generated for analysis. | 77 | 77 | . | | 78 | +.It Fl -completion-bash | | 79 | +Print source-able bash completion script for Node.js. | | 80 | +. | 78 | 81 | .It Fl -enable-fips | 79 | 82 | Enable FIPS-compliant crypto at startup. | 80 | 83 | Requires Node.js to be built with | |
Collapse file Copy file name to clipboard +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const { internalBinding } = require('internal/bootstrap/loaders'); | | 3 | +const { getOptions } = internalBinding('options'); | | 4 | + | | 5 | +function print(stream) { | | 6 | + const { options, aliases } = getOptions(); | | 7 | + const all_opts = [...options.keys(), ...aliases.keys()]; | | 8 | + | | 9 | + stream.write(`_node_complete() { | | 10 | + local cur_word options | | 11 | + cur_word="\${COMP_WORDS[COMP_CWORD]}" | | 12 | + if [[ "\${cur_word}" == -* ]] ; then | | 13 | + COMPREPLY=( $(compgen -W '${all_opts.join(' ')}' -- "\${cur_word}") ) | | 14 | + return 0 | | 15 | + else | | 16 | + COMPREPLY=( $(compgen -f "\${cur_word}") ) | | 17 | + return 0 | | 18 | + fi | | 19 | +} | | 20 | +complete -F _node_complete node node_g`); | | 21 | +} | | 22 | + | | 23 | +module.exports = { | | 24 | + print | | 25 | +}; |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 120 | 120 | NativeModule.require('internal/inspector_async_hook').setup(); | 121 | 121 | } | 122 | 122 |
| 123 | | - if (internalBinding('options').getOptions('--help')) { | | 123 | + const options = internalBinding('options'); | | 124 | + if (options.getOptions('--help')) { | 124 | 125 | NativeModule.require('internal/print_help').print(process.stdout); | 125 | 126 | return; | 126 | 127 | } | 127 | 128 |
| | 129 | + if (options.getOptions('--completion-bash')) { | | 130 | + NativeModule.require('internal/bash_completion').print(process.stdout); | | 131 | + return; | | 132 | + } | | 133 | + | 128 | 134 | if (isMainThread) { | 129 | 135 | mainThreadSetup.setupChildProcessIpcChannel(); | 130 | 136 | } | |
Collapse file Copy file name to clipboardExpand all lines: node.gyp +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 85 | 85 | 'lib/zlib.js', | 86 | 86 | 'lib/internal/assert.js', | 87 | 87 | 'lib/internal/async_hooks.js', | | 88 | + 'lib/internal/bash_completion.js', | 88 | 89 | 'lib/internal/buffer.js', | 89 | 90 | 'lib/internal/cli_table.js', | 90 | 91 | 'lib/internal/child_process.js', | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -223,6 +223,9 @@ PerProcessOptionsParser::PerProcessOptionsParser() { | 223 | 223 | kAllowedInEnvironment); | 224 | 224 |
| 225 | 225 | AddOption("--security-reverts", "", &PerProcessOptions::security_reverts); | | 226 | + AddOption("--completion-bash", | | 227 | + "print source-able bash completion script", | | 228 | + &PerProcessOptions::print_bash_completion); | 226 | 229 | AddOption("--help", | 227 | 230 | "print node command line options", | 228 | 231 | &PerProcessOptions::print_help); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -112,6 +112,7 @@ class PerProcessOptions { | 112 | 112 | bool zero_fill_all_buffers = false; | 113 | 113 |
| 114 | 114 | std::vector<std::string> security_reverts; | | 115 | + bool print_bash_completion = false; | 115 | 116 | bool print_help = false; | 116 | 117 | bool print_v8_help = false; | 117 | 118 | bool print_version = false; | |
|