Skip to content

bug: preserve nested command completion at cursor end #527

Description

@codeforester

Problem

The generated completion adapter must distinguish the current word from the completed words when COMP_CWORD points just past the last populated COMP_WORDS entry. If it clamps the cursor to the last existing word without appending an empty current word, an exact nested command is treated as a prefix and its child route is not offered.

The current main implementation has the correct behavior, but the staged cursor rewrite in the supplied checkout regresses it. This needs an explicit contract test and an implementation shape that cannot lose the empty current word during future completion changes.

Verified evidence

With a model containing admin and admin/user, the existing current-main contract is:

COMP_WORDS=(cursor admin)
COMP_CWORD=2
_cursor_complete
# COMPREPLY=user

The staged rewrite returns admin because it clamps COMP_CWORD to word_count - 1 and slices without appending an empty current word. The existing test fails when that rewrite is applied to current main.

Scope and acceptance criteria

  • Preserve exact nested-command completion when the cursor is at the end of COMP_WORDS.
  • Continue honoring cursors in the middle of the word array, option-value consumption, aliases, and the -- boundary.
  • Keep generated completion scratch state local and safe under unset or malformed completion variables.
  • Add regression coverage for the cursor-at-end exact-command case and the existing cursor matrix.

Validation

Run the CLI BATS tests, the full ./tests/validate.sh suite, and the repository quality gates.

Non-goals

No change to command declaration, parser, handler, or option-resolution semantics.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions