@@ -414,6 +414,90 @@ function _bash-it-doctor-errors() {
414414 _bash-it-doctor " ${BASH_IT_LOG_LEVEL_ERROR?} "
415415}
416416
417+ function _bash-it-doctor-check-profile-sourcing-grep() {
418+ _about ' checks if .bashrc is sourced from profile using grep'
419+ _param ' 1: profile file path'
420+ _group ' lib'
421+
422+ local profile_file=" ${1} "
423+ [[ ! -f " $profile_file " ]] && return 1
424+
425+ # Look for common patterns that source .bashrc
426+ command grep -qE ' (source|\.)\s+(~|\$HOME|"\$HOME")?/\.bashrc|if.*BASH_VERSION.*bashrc' " $profile_file "
427+ }
428+
429+ function _bash-it-doctor-check-profile-sourcing-test() {
430+ _about ' checks if .bashrc is actually sourced using brute force test'
431+ _group ' lib'
432+
433+ local bashrc=" $HOME /.bashrc"
434+ [[ ! -f " $bashrc " ]] && return 1
435+
436+ local backup_bashrc=" /tmp/.bashrc_backup_$$ "
437+
438+ # Move .bashrc aside
439+ command mv " $bashrc " " $backup_bashrc " 2> /dev/null || return 1
440+
441+ # Create test .bashrc that just echoes
442+ echo ' echo "__BASHRC_WAS_SOURCED__"' > " $bashrc "
443+
444+ # Test in login shell, capture output
445+ local output
446+ output=$( bash -l -c ' :' 2>&1 )
447+
448+ # Restore immediately
449+ command mv " $backup_bashrc " " $bashrc "
450+
451+ # Check if our marker appeared
452+ command grep -q " __BASHRC_WAS_SOURCED__" <<< " $output"
453+ }
454+
455+ function _bash-it-doctor-check-profile-sourcing() {
456+ _about ' checks if .bashrc is sourced from login shell profile files'
457+ _group ' lib'
458+
459+ local profile_file
460+ if [[ -f " $HOME /.bash_profile" ]]; then
461+ profile_file=" $HOME /.bash_profile"
462+ elif [[ -f " $HOME /.profile" ]]; then
463+ profile_file=" $HOME /.profile"
464+ else
465+ echo " ${YELLOW} No .bash_profile or .profile found${RESET} "
466+ echo " Login shells may not load bash-it configuration"
467+ return
468+ fi
469+
470+ # Show if it's a symlink
471+ if [[ -L " $profile_file " ]]; then
472+ echo " ${YELLOW} Note:${RESET} $profile_file is a symlink to $( readlink " $profile_file " ) "
473+ fi
474+
475+ # Try grep detection first (fast and safe)
476+ if _bash-it-doctor-check-profile-sourcing-grep " $profile_file " ; then
477+ echo " ${GREEN} ✓${RESET} .bashrc is sourced from $profile_file "
478+ return 0
479+ fi
480+
481+ # Grep didn't find it, try brute force test
482+ echo " Grep detection unclear, testing if .bashrc actually loads..."
483+ if _bash-it-doctor-check-profile-sourcing-test; then
484+ echo " ${GREEN} ✓${RESET} .bashrc is sourced (confirmed via test)"
485+ return 0
486+ fi
487+
488+ # Not sourced
489+ echo " ${RED} ✗${RESET} .bashrc is NOT sourced from $profile_file "
490+ echo " ${YELLOW} Warning:${RESET} bash-it will not load in login shells (Terminal.app, SSH sessions)"
491+ echo " ${YELLOW} Fix:${RESET} Add the following to $profile_file :"
492+ echo " "
493+ echo " if [ -n \"\$ BASH_VERSION\" ]; then"
494+ echo " if [ -f \"\$ HOME/.bashrc\" ]; then"
495+ echo " . \"\$ HOME/.bashrc\" "
496+ echo " fi"
497+ echo " fi"
498+ echo " "
499+ }
500+
417501function _bash-it-doctor-summary() {
418502 _about ' shows a comprehensive diagnostic summary for bug reports'
419503 _group ' lib'
@@ -494,7 +578,7 @@ function _bash-it-doctor-summary() {
494578 # Offer to update if behind and it's safe to do so
495579 local git_status untracked_files merge_base can_ff
496580 git_status=" $( git status --porcelain 2> /dev/null) "
497- untracked_files=" $( echo " $git_status " | grep -c ' ^??' || true) "
581+ untracked_files=" $( echo " $git_status " | command grep -c ' ^??' || true) "
498582
499583 # Check if we can fast-forward
500584 merge_base=" $( git merge-base HEAD " ${BASH_IT_REMOTE} /${BASH_IT_DEVELOPMENT_BRANCH} " 2> /dev/null) "
@@ -506,7 +590,7 @@ function _bash-it-doctor-summary() {
506590 # Only offer merge if:
507591 # 1. No modified/staged files (untracked are OK)
508592 # 2. Can fast-forward OR no untracked files that would conflict
509- if ! echo " $git_status " | grep -v ' ^??' -q; then
593+ if ! echo " $git_status " | command grep -v ' ^??' -q; then
510594 if [[ " $can_ff " == " true" ]] || [[ " $untracked_files " == " 0" ]]; then
511595 echo " "
512596 echo " Would you like to update now? This will merge ${BASH_IT_REMOTE} /${BASH_IT_DEVELOPMENT_BRANCH} into your current branch."
@@ -551,16 +635,28 @@ function _bash-it-doctor-summary() {
551635
552636 if [[ ${# config_files_to_check[@]} -gt 0 ]]; then
553637 for config_file_path in " ${config_files_to_check[@]} " ; do
554- if grep -i " bash.it\|bash_it" " $config_file_path " > /dev/null 2>&1 ; then
638+ if command grep -i " bash.it\|bash_it" " $config_file_path " > /dev/null 2>&1 ; then
555639 echo " From ${config_file_path} :"
556- grep -n -i " bash.it\|bash_it" -B2 -A2 " $config_file_path " 2> /dev/null
640+ command grep -n -i " bash.it\|bash_it" -B2 -A2 " $config_file_path " 2> /dev/null
557641 echo " "
558642 fi
559643 done
560644 else
561645 echo " No config files found (.bashrc, .bash_profile, .profile)"
562646 fi
563647
648+ # Profile Sourcing Check (macOS/Solaris/BSD)
649+ echo " ${BOLD} ## Profile Configuration${RESET} "
650+ case " $( uname -s) " in
651+ Darwin | SunOS | Illumos | * BSD)
652+ _bash-it-doctor-check-profile-sourcing
653+ ;;
654+ * )
655+ echo " Not applicable (Linux uses .bashrc for non-login shells by default)"
656+ ;;
657+ esac
658+ echo " "
659+
564660 # Enabled Components Summary
565661 echo " ${BOLD} ## Enabled Components${RESET} "
566662
0 commit comments