#!/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 "$@"