Skip to content

Fix bash completion for COMP_WORDBREAKS characters like colon - #1907

Closed
yoshibase wants to merge 11 commits into
fastapi:masterfrom
yoshibase:fix/issue-1905-bash-completion-wordbreaks
Closed

Fix bash completion for COMP_WORDBREAKS characters like colon#1907
yoshibase wants to merge 11 commits into
fastapi:masterfrom
yoshibase:fix/issue-1905-bash-completion-wordbreaks

Conversation

@yoshibase

@yoshibase yoshibase commented Jul 24, 2026

Copy link
Copy Markdown

Summary

Fixes #1905.

Bash splits COMP_WORDS on COMP_WORDBREAKS (including :) before the compspec runs, so values like alpine:latest arrived as separate tokens and completion saw the wrong incomplete prefix.

Changes

Updated COMPLETION_SCRIPT_BASH in typer/_completion_shared.py to:

  1. Rebuild the active word list from COMP_LINE / COMP_POINT before calling Typer
  2. Strip the COMP_WORDBREAKS-delimited suffix from each candidate before inserting into COMPREPLY (so bash appends latest after alpine: instead of replacing with alpine:latest)
  3. Tolerate unset COMP_WORDBREAKS and helper failures so the compspec does not abort mid-completion

Test plan

  • pytest tests/test_completion/test_completion_bash_wordbreaks.py
  • pytest tests/test_completion/ (full suite)
  • Integration case: split COMP_WORDS=(prog --name : l) with COMP_LINE="prog --name alpine:l" completes to alpine:latest

Label request: this is a bug fix — please add the bug label so check-labels can pass (contributors cannot set it).

yoshibase and others added 3 commits July 24, 2026 07:46
Rebuild COMP_WORDS from COMP_LINE before dispatching to Typer and strip the wordbreak prefix from candidates so values like alpine:latest complete correctly instead of returning empty or duplicating alpine:.
Make the compspec tolerate unset COMP_WORDBREAKS and helper failures, and
drive the integration test through the same Python entrypoint as other
completion tests so the autocomplete env var matches.
@yoshibase
yoshibase force-pushed the fix/issue-1905-bash-completion-wordbreaks branch from 5464a84 to ce3f524 Compare July 24, 2026 16:38
yoshibase added 6 commits July 24, 2026 09:42
Make the compspec tolerate unset COMP_WORDBREAKS and helper failures, and
drive the integration test through the same Python entrypoint as other
completion tests so the autocomplete env var matches.
Make the compspec tolerate unset COMP_WORDBREAKS and helper failures, and
drive the integration test through the same Python entrypoint as other
completion tests so the autocomplete env var matches.
Make the compspec tolerate unset COMP_WORDBREAKS and helper failures, and
drive the integration test through the same Python entrypoint as other
completion tests so the autocomplete env var matches.
Make the compspec tolerate unset COMP_WORDBREAKS and helper failures, and
drive the integration test through the same Python entrypoint as other
completion tests so the autocomplete env var matches.
Make the compspec tolerate unset COMP_WORDBREAKS and helper failures, and
drive the integration test through the same Python entrypoint as other
completion tests so the autocomplete env var matches.
Make the compspec tolerate unset COMP_WORDBREAKS and helper failures, and
drive the integration test through the same Python entrypoint as other
completion tests so the autocomplete env var matches.
@yoshibase

Copy link
Copy Markdown
Author

Tests are green after the COMP_WORDBREAKS harden follow-up. Could a maintainer please add the bug label so check-labels can pass? Contributors cannot set that label.

yoshibase added 2 commits July 24, 2026 15:26
Git Bash on Windows CI is detected as bash but does not exercise the
compspec path the same way; the integration test is Unix-only.
Exercise the helper's defensive error path so aggregate CI coverage remains
at 100 percent while the shell integration stays skipped on Windows.

@svlandeg svlandeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing as per the contribution guidelines.

@svlandeg svlandeg closed this Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bash completion breaks on COMP_WORDBREAKS characters like ":" (and add_completion_class doesn't cover --install-completion/--show-completion)

3 participants