Skip to content

Commit 4079439

Browse files
committed
Closes #1
1 parent 5400259 commit 4079439

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

.bashrc

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,46 @@ function ls() {
7272
function rm() {
7373
local arg recursive=0
7474
for arg in "$@"; do
75-
if [[ $arg == -[!-]*r* || $arg == -[!-]*R* || $arg == --recursive ]]; then
76-
recursive=1
77-
break
78-
fi
75+
case "$arg" in
76+
--recursive) recursive=1; break ;;
77+
--*) ;;
78+
-*[rR]*) recursive=1; break ;;
79+
esac
7980
done
81+
local rc
8082
if (( recursive )); then
83+
local target abs_target check_dir repo_root dirty=()
84+
for target in "$@"; do
85+
[[ $target == -* ]] && continue
86+
[[ ! -e $target ]] && continue
87+
abs_target=$(cd -- "$(dirname -- "$target")" 2>/dev/null && printf '%s/%s' "$(pwd)" "$(basename -- "$target")") || continue
88+
if [[ -d $abs_target ]]; then
89+
check_dir=$abs_target
90+
else
91+
check_dir=$(dirname -- "$abs_target")
92+
fi
93+
repo_root=$(command git -C "$check_dir" rev-parse --show-toplevel 2>/dev/null) || continue
94+
if [[ -n "$(command git -C "$repo_root" status --porcelain -- "$abs_target" 2>/dev/null)" ]]; then
95+
dirty+=("$target")
96+
fi
97+
done
98+
if (( ${#dirty[@]} > 0 )); then
99+
echo "rm: uncommitted git changes in:" >&2
100+
printf ' %s\n' "${dirty[@]}" >&2
101+
if [[ -t 0 ]]; then
102+
local reply
103+
read -r -p "Proceed anyway? [y/N] " reply
104+
[[ $reply =~ ^[Yy]$ ]] || { echo "Aborted." >&2; return 1; }
105+
fi
106+
fi
81107
command rm -f "$@"
108+
rc=$?
82109
else
83110
command rm "$@"
111+
rc=$?
84112
fi
85-
86-
if [[ $? -eq 0 ]]
87-
then
88-
ls -l
89-
else
90-
return $?
91-
fi
113+
(( rc == 0 )) && ls -l
114+
return $rc
92115
}
93116

94117
function cat() {

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Rule of thumb when adding something new: *runs in every interactive shell* (prom
5353
- `gh repo clone` auto-`cd`s into the cloned dir and sets the default repo.
5454
- `cat` is piped through `bat --style=plain --paging=never`, falling back to real `cat` if `bat` isn't installed.
5555
- `ls` with any `l` in the args gets `-GhLa` added.
56-
- `rm -r*` adds `-f` and runs `ls -l` afterward.
56+
- `rm -r*` adds `-f`, prompts before deleting any target that has uncommitted git changes, and runs `ls -l` afterward.
5757

5858
When suggesting shell changes, assume the user is running these wrappers — e.g. `git push --force` from their shell is actually `--force-with-lease`.
5959

0 commit comments

Comments
 (0)