blob: 467fec2477a4287b9f286e0a052c5799e4619079 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/bin/bash
if [ ! -t 1 ] || [ -n "$UNSAFE_RM" ]; then
# shellcheck disable=SC2068
exec /bin/rm "$@"
fi
# stop me from being stupid
OPTIND=0
for o in "$@"; do
OPTIND+=1
if [ -d "$o" ] || [ -f "$o" ]; then
break
fi
[ "$o" = "-r" ] && recurse=1
[ "$o" = "-f" ] && force=1
[ "$o" = "-rf" ] && force=1 && recurse=1
[ "$o" = "-h" ] && {
printf "usage: saferm\n\n"
exit 0
}
done
if [ -n "${force}" ] && [ -n "${recurse}" ]; then
tput setaf 1
(
echo "!"
echo "!" "recursive force not allowed"
echo "!"
) >&2
tput sgr0
exit 1
fi
tput setaf 1
(
for ((idx = OPTIND; idx <= $#; idx++)); do
if [ -d "${!idx}" ]; then
exa --color=never --all --tree "${!idx}" >&2
echo "!"
echo "!" "$(du -sh "${!idx}")"
echo "!" "$(fd --no-ignore --type file . "${!idx}" | wc -l)" "files"
echo "!" "$(fd --no-ignore --type directory . "${!idx}" | wc -l)" "directories"
echo "!"
else
echo "${!idx}"
fi
done
) >&2
tput sgr0
# shellcheck disable=SC2068
exec /bin/rm -I --one-file-system "$@"
|