Skip to content

Commit a336f99

Browse files
seefoodclaude
andcommitted
Use 'command' prefix to bypass user aliases in core functions
Addresses review feedback from @akinomyoga on PR Bash-it#2342. **Problem:** Users may have aliases like: - `alias mv='mv -i'` (prompts for confirmation) - `alias grep='grep --color=always'` (breaks parsing) - `alias rm='rm -i'` (prompts for confirmation) These aliases can break bash-it core functions that assume standard command behavior. **Solution:** Prefix sensitive commands with `command` to bypass aliases: - `command mv` - ensures atomic file operations without prompts - `command grep` - ensures predictable output format - Applied to all mv/grep calls in doctor functions **Documentation:** Added coding standard to CLAUDE.md: - Documents the `command` prefix pattern - Lists common commands that should be prefixed - Explains why this prevents surprises in core functions This is a defensive programming practice that makes bash-it more robust against varied user configurations. Thanks to @akinomyoga for catching this! Related to PR Bash-it#2342 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f15f639 commit a336f99

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

CLAUDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,9 @@ bash-it search docker
134134
- Follow existing code style in the repository
135135
- Add appropriate metadata using composure functions
136136
- Components should handle missing dependencies gracefully
137+
- **Prefix sensitive commands with `command`** to bypass user aliases:
138+
- `command mv` instead of `mv` (users may have `alias mv='mv -i'`)
139+
- `command grep` instead of `grep` (users may have custom grep flags)
140+
- `command rm` instead of `rm` (users may have `alias rm='rm -i'`)
141+
- Apply to any command that could be aliased and break core functionality
142+
- This prevents surprises from user's alias configurations in bash-it core functions

lib/helpers.bash

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ function _bash-it-doctor-check-profile-sourcing-grep() {
423423
[[ ! -f "$profile_file" ]] && return 1
424424

425425
# Look for common patterns that source .bashrc
426-
grep -qE '(source|\.)\s+(~|\$HOME|"\$HOME")?/\.bashrc|if.*BASH_VERSION.*bashrc' "$profile_file"
426+
command grep -qE '(source|\.)\s+(~|\$HOME|"\$HOME")?/\.bashrc|if.*BASH_VERSION.*bashrc' "$profile_file"
427427
}
428428

429429
function _bash-it-doctor-check-profile-sourcing-test() {
@@ -446,10 +446,10 @@ function _bash-it-doctor-check-profile-sourcing-test() {
446446
output=$(bash -l -c ':' 2>&1)
447447

448448
# Restore immediately
449-
mv "$backup_bashrc" "$bashrc"
449+
command mv "$backup_bashrc" "$bashrc"
450450

451451
# Check if our marker appeared
452-
grep -q "__BASHRC_WAS_SOURCED__" <<< "$output"
452+
command grep -q "__BASHRC_WAS_SOURCED__" <<< "$output"
453453
}
454454

455455
function _bash-it-doctor-check-profile-sourcing() {
@@ -578,7 +578,7 @@ function _bash-it-doctor-summary() {
578578
# Offer to update if behind and it's safe to do so
579579
local git_status untracked_files merge_base can_ff
580580
git_status="$(git status --porcelain 2> /dev/null)"
581-
untracked_files="$(echo "$git_status" | grep -c '^??' || true)"
581+
untracked_files="$(echo "$git_status" | command grep -c '^??' || true)"
582582

583583
# Check if we can fast-forward
584584
merge_base="$(git merge-base HEAD "${BASH_IT_REMOTE}/${BASH_IT_DEVELOPMENT_BRANCH}" 2> /dev/null)"
@@ -590,7 +590,7 @@ function _bash-it-doctor-summary() {
590590
# Only offer merge if:
591591
# 1. No modified/staged files (untracked are OK)
592592
# 2. Can fast-forward OR no untracked files that would conflict
593-
if ! echo "$git_status" | grep -v '^??' -q; then
593+
if ! echo "$git_status" | command grep -v '^??' -q; then
594594
if [[ "$can_ff" == "true" ]] || [[ "$untracked_files" == "0" ]]; then
595595
echo ""
596596
echo "Would you like to update now? This will merge ${BASH_IT_REMOTE}/${BASH_IT_DEVELOPMENT_BRANCH} into your current branch."
@@ -635,9 +635,9 @@ function _bash-it-doctor-summary() {
635635

636636
if [[ ${#config_files_to_check[@]} -gt 0 ]]; then
637637
for config_file_path in "${config_files_to_check[@]}"; do
638-
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
639639
echo "From ${config_file_path}:"
640-
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
641641
echo ""
642642
fi
643643
done

0 commit comments

Comments
 (0)