Skip to content

feat: bash completion works on stock macOS bash 3.2 (no bash-completion dep)#28

Merged
alexzhangs merged 1 commit into
developfrom
feat/bash-completion-stock-macos
Jun 10, 2026
Merged

feat: bash completion works on stock macOS bash 3.2 (no bash-completion dep)#28
alexzhangs merged 1 commit into
developfrom
feat/bash-completion-stock-macos

Conversation

@alexzhangs

Copy link
Copy Markdown
Owner

Summary

Tab completion in 0.6.0 silently does nothing on stock macOS because:

  • /bin/bash is 3.2.57
  • bash-completion@2 requires bash 4+ and bails silently
  • completions/xsh.bash's first line is _init_completion || return → returns immediately

Three small coordinated changes make it work out of the box:

1. completions/xsh.bash_init_completion fallback shim

Defined 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 <= 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

Users don't have to touch ~/.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

That copy was a no-op on macOS (no such dir) and double-sourced on Linux once .xshrc auto-source landed.

Verified

Stock /bin/bash 3.2.57, no bash-completion package installed:

$ xsh <TAB><TAB>
load unload update list imports unimports import unimport help debug
version versions upgrade calls call exec log lib-manager lib-dev-manager
+ 200+ LPUEs from loaded libs

$ xsh load <TAB><TAB>
xsh-lib/aws  xsh-lib/core  xsh-lib/git

Also verified the shim does NOT override a pre-existing _init_completion (when bash-completion is loaded earlier).

Test plan

  • CI green (matrix: bash 3.2 macOS / bash 4.4 rocky / bash 5.x macOS+Linux)
  • After merge: existing 0.6.0 users get the fix by re-running bash install.sh -f -s or via xsh upgrade

…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

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.29%. Comparing base (e5df7b1) to head (2bbd27a).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alexzhangs alexzhangs merged commit 056155b into develop Jun 10, 2026
10 checks passed
@alexzhangs alexzhangs deleted the feat/bash-completion-stock-macos branch June 10, 2026 15:19
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