@@ -41,6 +41,79 @@ function _bash-it-install-enable() {
4141 done
4242}
4343
44+ # Ensure .bashrc is sourced from profile files on macOS/BSD/Solaris
45+ function _bash-it-install-ensure-bashrc-sourcing() {
46+ # Only needed on platforms where login shells don't source .bashrc
47+ case " $( uname -s) " in
48+ Darwin | SunOS | Illumos | * BSD) ;;
49+ * ) return 0 ;; # Not needed on Linux
50+ esac
51+
52+ # Find which profile file exists
53+ local profile_file
54+ if [[ -f " $HOME /.bash_profile" ]]; then
55+ profile_file=" $HOME /.bash_profile"
56+ elif [[ -f " $HOME /.profile" ]]; then
57+ profile_file=" $HOME /.profile"
58+ else
59+ # No profile file exists, create .bash_profile
60+ profile_file=" $HOME /.bash_profile"
61+ echo -e " ${echo_yellow:- } Creating $profile_file to source .bashrc${echo_normal:- } "
62+ fi
63+
64+ # Check if already sourced (reuse helper from doctor)
65+ if _bash-it-doctor-check-profile-sourcing-grep " $profile_file " 2> /dev/null; then
66+ return 0 # Already configured
67+ fi
68+
69+ # Not sourced, offer to add it
70+ echo " "
71+ echo -e " ${echo_yellow:- } Warning: .bashrc is not sourced from $profile_file ${echo_normal:- } "
72+ echo " On macOS/BSD/Solaris, login shells won't load bash-it without this."
73+ echo " "
74+
75+ local RESP
76+ if [[ -z " ${silent:- } " ]]; then
77+ read -r -e -n 1 -p " Would you like to add .bashrc sourcing to $profile_file ? [Y/n] " RESP
78+ case $RESP in
79+ [nN])
80+ echo " "
81+ echo -e " ${echo_orange:- } Skipping. You can add this manually later:${echo_normal:- } "
82+ echo " "
83+ echo " if [ -n \"\$ {BASH_VERSION-}\" ]; then"
84+ echo " if [ -f \"\$ HOME/.bashrc\" ]; then"
85+ echo " . \"\$ HOME/.bashrc\" "
86+ echo " fi"
87+ echo " fi"
88+ echo " "
89+ return 0
90+ ;;
91+ esac
92+ fi
93+
94+ # Backup profile file if it exists
95+ if [[ -f " $profile_file " ]]; then
96+ local backup_file
97+ backup_file=" ${profile_file} .bak.$( date +%Y%m%d_%H%M%S) "
98+ command cp " $profile_file " " $backup_file "
99+ echo -e " ${echo_green:- } Backed up $profile_file to $backup_file ${echo_normal:- } "
100+ fi
101+
102+ # Add the sourcing snippet
103+ cat >> " $profile_file " << 'EOF '
104+
105+ # Source .bashrc if running bash
106+ if [ -n "${BASH_VERSION-}" ]; then
107+ if [ -f "$HOME/.bashrc" ]; then
108+ . "$HOME/.bashrc"
109+ fi
110+ fi
111+ EOF
112+
113+ echo -e " ${echo_green:- } ✓ Added .bashrc sourcing to $profile_file ${echo_normal:- } "
114+ echo " "
115+ }
116+
44117# Back up existing profile
45118function _bash-it-install-backup-config() {
46119 test -w " ${HOME?} /${CONFIG_FILE?} " \
222295 _bash-it-profile-load " default"
223296fi
224297
298+ # Ensure .bashrc sourcing is set up on macOS/BSD/Solaris
299+ _bash-it-install-ensure-bashrc-sourcing
300+
225301echo " "
226302echo -e " ${echo_green:- } Installation finished successfully! Enjoy bash-it!${echo_normal:- } "
227303echo -e " ${echo_green:- } To start using it, open a new tab or 'source ~/${CONFIG_FILE?} '.${echo_normal:- } "
0 commit comments