feat: bash completion works on stock macOS bash 3.2 (no bash-completion dep)#28
Merged
Merged
Conversation
…on dep) Stock macOS /bin/bash is 3.2.57. bash-completion@2 requires bash 4+ and silently bails on 3.2, so completions/xsh.bash's first line — _init_completion || return — exited silently and tab-completion did nothing. Three coordinated changes make tab-completion work out of the box on stock macOS: 1. completions/xsh.bash: define a minimal _init_completion shim if not already present. Guarded so a real bash-completion load (now or later) wins. Defensive cword<=0 guard matches real _init_completion semantics and avoids bash 3.2's bad-array-subscript error on COMP_WORDS[-1]. 2. .xshrc: auto-source the completion file. Reaches every bash user without requiring them to edit ~/.bash_profile or rely on /etc/bash_completion.d discovery (which doesn't exist on stock macOS). 3. install.sh: drop the now-redundant /etc/bash_completion.d/xsh copy. It was a no-op on macOS (no such dir) and double-sourced on Linux once .xshrc auto-source landed. Verified on /bin/bash 3.2.57 with no bash-completion installed: 19 built-in completions + 'xsh load <TAB>' → 3 known public libs. Also verified that a pre-existing _init_completion is preserved (the shim doesn't override). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #28 +/- ##
===========================================
+ Coverage 63.13% 63.29% +0.15%
===========================================
Files 3 3
Lines 792 790 -2
===========================================
Hits 500 500
+ Misses 292 290 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tab completion in 0.6.0 silently does nothing on stock macOS because:
/bin/bashis 3.2.57bash-completion@2requires bash 4+ and bails silentlycompletions/xsh.bash's first line is_init_completion || return→ returns immediatelyThree small coordinated changes make it work out of the box:
1.
completions/xsh.bash—_init_completionfallback shimDefined only if not already present (so a real bash-completion load wins, whether earlier or later). Sets the same four caller-local variables the completer reads. Defensive
cword <= 0guard matches real_init_completionsemantics and avoids bash 3.2's bad-array-subscript error on${COMP_WORDS[-1]}.2.
.xshrc— auto-source the completion fileUsers don't have to touch
~/.bash_profileor rely on/etc/bash_completion.d/discovery (which doesn't exist on stock macOS).3.
install.sh— drop the now-redundant/etc/bash_completion.d/xshcopyThat copy was a no-op on macOS (no such dir) and double-sourced on Linux once
.xshrcauto-source landed.Verified
Stock
/bin/bash3.2.57, no bash-completion package installed:Also verified the shim does NOT override a pre-existing
_init_completion(when bash-completion is loaded earlier).Test plan
bash install.sh -f -sor viaxsh upgrade