#!/bin/bash set -e [ -n "$DEBUG" ] && set -x 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 rm_prompt_arg=-I files=() for ((idx = OPTIND; idx <= $#; idx++)); do if [ -e "${!idx}" ]; then if [ -d "${!idx}" ]; then tput setaf 1 ( exa --color=never --all --tree -- "${!idx}" >&2 echo "!" echo "!" "$(du -sh --total -- "${!idx}" | grep total)" echo "!" "$(fd --no-ignore --type file -- . "${!idx}" | wc -l)" "files" echo "!" "$(fd --no-ignore --type directory -- . "${!idx}" | wc -l)" "directories" echo "!" ) >&2 tput sgr0 else tput setaf 1 echo "${!idx}" >&2 files+=("${!idx}") fi fi done if [ ${#files[@]} -gt 0 ]; then rm_prompt_arg=-i tput setaf 1 ( echo "!" echo "!" "$(du -sh --total -- "${files[@]}" | grep total)" echo "!" "${#files[@]}" "files" echo "!" ) >&2 tput sgr0 fi # shellcheck disable=SC2068 exec /bin/rm ${rm_prompt_arg} --one-file-system "$@"