diff --git a/src/cli/bashCompletionRegistration.ts b/src/cli/bashCompletionRegistration.ts index 4bb8361bdc..327b82226f 100644 --- a/src/cli/bashCompletionRegistration.ts +++ b/src/cli/bashCompletionRegistration.ts @@ -5,16 +5,17 @@ export const bashCompletionScript = (name: string): string => { return `_incur_complete_${id}() { local IFS=$'\\013' local _COMPLETE_INDEX=\${COMP_CWORD} - local _completions - _completions=( $( + local _completions _output + if ! _output=$( export COMPLETE="bash" export _COMPLETE_INDEX="$_COMPLETE_INDEX" ${command} -- "\${COMP_WORDS[@]}" - ) ) - if [[ $? != 0 ]]; then + ); then unset COMPREPLY return fi + # Split the protocol records without expanding pathname patterns. + read -r -d '' -a _completions < <(printf '%s\\0' "$_output") local _nospace=false local _nospace_marker=$'\\001' local _c diff --git a/tests/boundary/cli/bashCompletionRegistration.test.ts b/tests/boundary/cli/bashCompletionRegistration.test.ts index 94255d53aa..3d7596b7a5 100644 --- a/tests/boundary/cli/bashCompletionRegistration.test.ts +++ b/tests/boundary/cli/bashCompletionRegistration.test.ts @@ -21,7 +21,7 @@ complete -p rea || exit rea() { [[ "$COMPLETE" == bash && "$_COMPLETE_INDEX" == 1 ]] || return 1 [[ "$1" == -- && "$2" == rea && "$3" == ana ]] || return 1 - printf 'analyze\\013analyze-web-bundle\\013' + printf 'analyze\\013analyze-web-bundle\\013*.json\\013' } COMP_WORDS=(rea ana) COMP_CWORD=1 @@ -33,7 +33,7 @@ printf '%s\\n' "\${COMPREPLY[@]}" ); expect(stderr).toBe(""); expect(stdout).toContain("-F _incur_complete_rea rea"); - expect(stdout).toContain("\nanalyze\nanalyze-web-bundle\n"); + expect(stdout).toContain("\nanalyze\nanalyze-web-bundle\n*.json\n"); }, );