Skip to content

Commit 3465717

Browse files
committed
fix: extract completions from first valid line, discard Node.js preamble
1 parent affd121 commit 3465717

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

src/claude-code/install.sh

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -540,12 +540,14 @@ setup_completions() {
540540
local bash_comp_raw=""
541541
local bash_comp_output=""
542542
bash_comp_raw=$(timeout 30 claude completions bash </dev/null 2>/dev/null) || true
543-
# Strip ANSI escape codes and leading blank lines so that preamble noise
544-
# does not cause valid completion scripts to be rejected.
545-
bash_comp_output=$(printf '%s' "${bash_comp_raw}" | sed "s/${esc}\[[0-9;]*[a-zA-Z]//g" | sed '/./,$!d')
546-
if [[ "${bash_comp_output}" == "_"* ]] || [[ "${bash_comp_output}" == "#"* ]]; then
543+
# Strip ANSI codes then extract from the first valid completion line onwards.
544+
# This discards any Node.js warnings or other preamble that precede the script.
545+
bash_comp_output=$(printf '%s' "${bash_comp_raw}" |
546+
sed "s/${esc}\[[0-9;]*[a-zA-Z]//g" |
547+
sed -n '/^[_#]/,$p')
548+
if [[ -n "${bash_comp_output}" ]]; then
547549
printf '%s\n' "${bash_comp_output}" >"${bash_comp_dir}/claude"
548-
elif [[ -n "${bash_comp_output}" ]]; then
550+
elif [[ -n "${bash_comp_raw}" ]]; then
549551
log_warn "Skipping bash completions: output does not look like a valid completion script."
550552
else
551553
log_debug "Skipping bash completions: no output from claude completions bash."
@@ -558,12 +560,13 @@ setup_completions() {
558560
local zsh_comp_raw=""
559561
local zsh_comp_output=""
560562
zsh_comp_raw=$(timeout 30 claude completions zsh </dev/null 2>/dev/null) || true
561-
# Strip ANSI escape codes and leading blank lines so that preamble noise
562-
# does not cause valid completion scripts to be rejected.
563-
zsh_comp_output=$(printf '%s' "${zsh_comp_raw}" | sed "s/${esc}\[[0-9;]*[a-zA-Z]//g" | sed '/./,$!d')
564-
if [[ "${zsh_comp_output}" == "#compdef"* ]]; then
563+
# Strip ANSI codes then extract from the first valid completion line onwards.
564+
zsh_comp_output=$(printf '%s' "${zsh_comp_raw}" |
565+
sed "s/${esc}\[[0-9;]*[a-zA-Z]//g" |
566+
sed -n '/^#compdef/,$p')
567+
if [[ -n "${zsh_comp_output}" ]]; then
565568
printf '%s\n' "${zsh_comp_output}" >/usr/share/zsh/site-functions/_claude
566-
elif [[ -n "${zsh_comp_output}" ]]; then
569+
elif [[ -n "${zsh_comp_raw}" ]]; then
567570
log_warn "Skipping zsh completions: output does not look like a valid completion script."
568571
else
569572
log_debug "Skipping zsh completions: no output from claude completions zsh."
@@ -582,12 +585,13 @@ setup_completions() {
582585
local fish_comp_raw=""
583586
local fish_comp_output=""
584587
fish_comp_raw=$(timeout 30 claude completions fish </dev/null 2>/dev/null) || true
585-
# Strip ANSI escape codes and leading blank lines so that preamble noise
586-
# does not cause valid completion scripts to be rejected.
587-
fish_comp_output=$(printf '%s' "${fish_comp_raw}" | sed "s/${esc}\[[0-9;]*[a-zA-Z]//g" | sed '/./,$!d')
588-
if [[ "${fish_comp_output}" == "complete"* ]]; then
588+
# Strip ANSI codes then extract from the first valid completion line onwards.
589+
fish_comp_output=$(printf '%s' "${fish_comp_raw}" |
590+
sed "s/${esc}\[[0-9;]*[a-zA-Z]//g" |
591+
sed -n '/^complete/,$p')
592+
if [[ -n "${fish_comp_output}" ]]; then
589593
printf '%s\n' "${fish_comp_output}" >"${fish_comp_dir}/claude.fish"
590-
elif [[ -n "${fish_comp_output}" ]]; then
594+
elif [[ -n "${fish_comp_raw}" ]]; then
591595
log_warn "Skipping fish completions: output does not look like a valid completion script."
592596
else
593597
log_debug "Skipping fish completions: no output from claude completions fish."

0 commit comments

Comments
 (0)