Files
reverse-engineering-anything/src/cli/bashCompletionRegistration.ts
T
ShuaixinHuang fdd4aefd18 fix(cli): preserve literal Bash completion candidates (#9153)
* test(process): align symlink fixture with filesystem checkpoints

* test(frida): assert the CLI spawn Evidence contract

* test(mcp): use an unsupported analysis-view parent

* test(browser): separate source-location line bounds from parity

* fix(cli): preserve literal Bash completion candidates
2026-11-07 01:28:34 +08:00

39 lines
1.3 KiB
TypeScript

/** Register Incur's dynamic Bash protocol, including macOS system Bash 3.2. */
export const bashCompletionScript = (name: string): string => {
const id = name.replace(/[^a-zA-Z0-9_]/gu, "_");
const command = `'${name.replaceAll("'", "'\\''")}'`;
return `_incur_complete_${id}() {
local IFS=$'\\013'
local _COMPLETE_INDEX=\${COMP_CWORD}
local _completions _output
if ! _output=$(
export COMPLETE="bash"
export _COMPLETE_INDEX="$_COMPLETE_INDEX"
${command} -- "\${COMP_WORDS[@]}"
); 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
COMPREPLY=()
for _c in "\${_completions[@]}"; do
if [[ "$_c" == *"$_nospace_marker" ]]; then
_nospace=true
COMPREPLY+=("\${_c%"$_nospace_marker"}")
else
COMPREPLY+=("$_c")
fi
done
if [[ $_nospace == true ]] && type compopt >/dev/null 2>&1; then
compopt -o nospace
fi
return 0
}
complete -o default -o bashdefault -o nosort -F _incur_complete_${id} ${command} 2>/dev/null ||
complete -o default -o bashdefault -F _incur_complete_${id} ${command}`;
};