Auto-fix .bashrc sourcing during install.sh on macOS/BSD/Solaris#2343
Merged
seefood merged 2 commits intoBash-it:masterfrom Oct 4, 2025
Merged
Auto-fix .bashrc sourcing during install.sh on macOS/BSD/Solaris#2343seefood merged 2 commits intoBash-it:masterfrom
seefood merged 2 commits intoBash-it:masterfrom
Conversation
Implements the auto-fix portion of issue Bash-it#1455 (Solaris/Illumos support). **Problem:** On macOS, BSD, Solaris, and Illumos, login shells source .bash_profile or .profile, NOT .bashrc. Users would install bash-it successfully but find it doesn't load in: - Terminal.app (macOS default terminal) - SSH sessions - Any new login shell **Solution:** During installation, automatically detect and fix .bashrc sourcing: 1. **Platform Detection:** - Only runs on affected platforms (Darwin, SunOS, Illumos, *BSD) - Linux users unaffected (no extra prompts) 2. **Smart Detection:** - Reuses `_bash-it-doctor-check-profile-sourcing-grep()` from doctor - Fast grep-based detection of existing sourcing patterns - Skips if already configured 3. **Interactive Prompt:** - Prompts user: "Would you like to add .bashrc sourcing? [Y/n]" - Shows manual instructions if user declines - Silent mode: auto-accepts (safe default behavior) 4. **Safe Modifications:** - Backs up profile file with timestamp before modifying - Uses `command cp` to bypass aliases - Creates .bash_profile if no profile file exists - Appends standard BASH_VERSION check snippet **User Experience:** Before (macOS user): ``` $ bash-it install Installation finished successfully! $ # opens new terminal... bash-it doesn't work! 😞 ``` After (macOS user): ``` $ bash-it install ... Warning: .bashrc is not sourced from /Users/me/.bash_profile Would you like to add .bashrc sourcing? [Y/n] y ✓ Added .bashrc sourcing to /Users/me/.bash_profile Installation finished successfully! $ # opens new terminal... bash-it works! 😃 ``` **Testing:** - ✅ Shellcheck passes - ✅ Detection logic tested - ✅ Silent mode compatible - ✅ Handles missing profile files Closes Bash-it#1455 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
akinomyoga
reviewed
Oct 4, 2025
Apply defensive shell scripting best practice to prevent errors when
`set -u` (nounset) is active in user shells. Replace `$BASH_VERSION`
with `${BASH_VERSION-}` in both:
- Manual instructions shown to users
- Auto-generated .bash_profile snippet
This ensures the check works correctly even when BASH_VERSION is unset
(e.g., when running under non-bash shells like dash or sh).
Also documents this pattern in CLAUDE.md for future development.
Addresses review feedback from @akinomyoga in PR Bash-it#2343
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Contributor
Author
|
Fixed the ${BASH_VERSION-} usage in 9ec149a per review feedback. Also documented this pattern in CLAUDE.md for future reference. Thanks @akinomyoga! |
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
Automatically sets up .bashrc sourcing during bash-it installation on macOS, BSD, Solaris, and Illumos systems.
This PR builds on the detection capability added in #2342 by implementing the auto-fix during installation.
Problem
On macOS/BSD/Solaris, login shells source
.bash_profileor.profile, NOT.bashrc.Without this fix, users would:
./install.shsuccessfullyMany users wouldn't know why or how to fix it.
Solution
During installation, automatically detect and fix .bashrc sourcing:
1. Platform Detection
2. Smart Detection
_bash-it-doctor-check-profile-sourcing-grep()from Detect .bashrc sourcing issues on macOS/BSD/Solaris in doctor #23423. Interactive Prompt
-sflag): auto-accepts (safe default)4. Safe Modifications
command cpto bypass user aliases (defensive programming).bash_profileif no profile file existsUser Experience
Before (macOS user):
After (macOS user):
Silent mode:
$ ./install.sh -s ... ✓ Added .bashrc sourcing to /Users/me/.bash_profile Installation finished successfully!Code Snippet Added
The installer adds this standard snippet to the profile file:
Implementation Details
command cpto bypass aliasesTesting
Closes
Closes #1455 (Solaris/Illumos support)
Related
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]