mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
813368c037
Currently, when using the bash completions for node the normal completions for filenames directories do not work. For example, after finding a node completion and then wanting to use tab completion for a filename in the test directory, it is only possible to get the name of the test directory completed, followed by a space. What is expected is to be able to continue with tab completion for directories. This commit adds options to the complete command to enable default bash completions. PR-URL: https://github.com/nodejs/node/pull/33744 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
36 lines
1023 B
JavaScript
36 lines
1023 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const child_process = require('child_process');
|
|
const { debuglog, inspect } = require('util');
|
|
const debug = debuglog('test');
|
|
|
|
const p = child_process.spawnSync(
|
|
process.execPath, [ '--completion-bash' ]);
|
|
assert.ifError(p.error);
|
|
|
|
const output = p.stdout.toString().trim().replace(/\r/g, '');
|
|
debug(output);
|
|
|
|
const prefix = `_node_complete() {
|
|
local cur_word options
|
|
cur_word="\${COMP_WORDS[COMP_CWORD]}"
|
|
if [[ "\${cur_word}" == -* ]] ; then
|
|
COMPREPLY=( $(compgen -W '`.replace(/\r/g, '');
|
|
const suffix = `' -- "\${cur_word}") )
|
|
return 0
|
|
else
|
|
COMPREPLY=( $(compgen -f "\${cur_word}") )
|
|
return 0
|
|
fi
|
|
}
|
|
complete -o filenames -o nospace -o bashdefault -F _node_complete node node_g`
|
|
.replace(/\r/g, '');
|
|
|
|
assert.ok(
|
|
output.includes(prefix),
|
|
`Expect\n\n ${inspect(output)}\n\nto include\n\n${inspect(prefix)}`);
|
|
assert.ok(
|
|
output.includes(suffix),
|
|
`Expect\n\n ${inspect(output)}\n\nto include\n\n${inspect(suffix)}`);
|