Skip to content

completion/aliases: pass the last alias word as the preceding word - #2419

Merged
seefood merged 2 commits into
Bash-it:masterfrom
seefood:alias-completion/001-prec-word
Oct 24, 2026
Merged

seefood merged 2 commits into
Bash-it:masterfrom
seefood:alias-completion/001-prec-word

Conversation

@seefood

@seefood seefood commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Description

For an alias such as alias kubectx='kubectl config use-context', the generated completion wrapper set the preceding word ($3) to config use-context instead of the last alias word, use-context. The wrapper stripped only the command from cmd args.

Completion functions that read $3 rather than calling _get_comp_words_by_ref (cobra-generated scripts do the latter) received the wrong value. The wrapper now passes the last alias word, quoted with printf %q at generation time like the other embedded values.

Motivation and Context

Found while investigating #2264. This does not fix that issue. I could not reproduce it on current master: with real kubectl v1.37.1, kubectx mi<TAB> and kubectx k3s-<TAB> complete correctly with and without this change (bash 5.1.16, system and aliases completions enabled, source <(kubectl completion bash) before bash-it). This is a separate, small correction.

How Has This Been Tested?

  • Added a bats test that calls the generated wrapper for a multi-word alias and checks $1, $2, $3, COMP_LINE, COMP_WORDS and COMP_CWORD. It fails before the change and passes after.
  • test/run test/completion/aliases.completion.bats: 4/4 pass.
  • pre-commit hooks (shellcheck, shfmt) pass.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

🤖 Generated with Claude Code

seefood and others added 2 commits October 24, 2026 15:20
The wrapper stripped only the command from 'cmd args', so $3 held all alias
arguments ('config use-context') instead of the last word ('use-context').

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ash 3.2

The init callback ends a 'read -d ""' at EOF (status 1), which bash 3.2
propagates through bats' errexit when load is called directly. Other tests
in the file avoid this by using 'run'; this one needs the wrapper defined in
the current shell, so disable errexit around load and assert the wrapper exists.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@seefood
seefood merged commit b17fdcb into Bash-it:master Oct 24, 2026
6 checks passed
@seefood
seefood deleted the alias-completion/001-prec-word branch October 24, 2026 12:48
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.

1 participant