Skip to content

bash: restore native variable completion fallback - #260

Open
kudala-bharani wants to merge 2 commits into
tqdm:mainfrom
kudala-bharani:fix/bash-variable-completion
Open

kudala-bharani wants to merge 2 commits into
tqdm:mainfrom
kudala-bharani:fix/bash-variable-completion

Conversation

@kudala-bharani

@kudala-bharani kudala-bharani commented Sep 24, 2026 •

Copy link
Copy Markdown

Fixes #172.

Once shtab's completion function is registered, Bash stops completing variable names such as $BASH_V. Adding -o bashdefault lets Bash try its native completion when the generated function has no matches. This handles $VAR, ${VAR, and double-quoted forms without duplicating Bash's variable parsing. It also restores native tilde-user completion, but doesn't enable the separate filename fallback (-o default).

When file completion produces no candidates, the generated function also clears filenames mode before native fallback. Otherwise Bash 4+ escapes $ inside quoted variable names. Filename handling stays enabled when there are actual file candidates.

The tests press Tab in a real Bash session. The 24 variable cases cover positional arguments, --pid, file and directory options, --, and redirection. There's also a check that an ordinary filename prefix isn't completed as an option value. Removing the filename-mode reset reproduces six quoted-variable failures on Bash 5.2.

Validation:

  • Linux, Python 3.14.7 / Bash 5.2: 119 passed, 67 skipped.
  • macOS, Python 3.12.13 / Bash 3.2: 127 passed, 59 skipped.
  • Coverage: 90.55% on both platforms (required: 85%).
  • pre-commit run --all-files: passed.
  • Existing directory trailing-slash, file completion, and redirection tests pass on Bash 5.2.

The generated Bash examples intentionally change to include the native fallback and filename-mode guard; other shell generators are unchanged.

@kudala-bharani

Copy link
Copy Markdown
Author

Found the Linux failure: filename mode stayed enabled when no files matched, which made Bash escape $ during quoted variable completion. This now gets cleared before native fallback. I also added coverage for file and directory options. The full suite passes on Linux/Bash 5.2 and macOS/Bash 3.2, and pre-commit passes.

This branch has not been deployed

No deployments
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.

Completion of environment variable names

1 participant