#!/usr/bin/env bash ## An rm wrapper that prints the absolute paths of the files that will be ## removed and then requests confirmation once before removal. ## ## Usage: remove ... ## ## Dependencies: GNU coreutils, GNU sed set -euo pipefail shopt -s inherit_errexit [[ " $* " =~ ' --help ' ]] && sed -n 's/^## *//p' "$0" && exit file_count=0 for arg; do [[ -e $arg || -L $arg ]] && realpath -s -- "$arg" && (( ++file_count )) done if (( file_count == 0 )) || { read -rp 'Remove files? ' input && [[ $input =~ ^[Yy] ]]; }; then rm "$@" fi