#!/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 <rm-arg>...
##
## Dependencies: GNU coreutils, GNU sed

set -euo pipefail
shopt -s inherit_errexit

die() { echo "${0##*/}: $1" >&2; exit 1; }

[[ " $* " =~ ' --help ' ]] && sed -n 's/^## \?//p' "$0" && exit
(( $# )) || die 'missing argument'

file_count=0

for arg; do
  [[ -e $arg || -L $arg ]] && realpath -s -- "$arg" && (( ++file_count ))
done

if (( file_count == 0 )) ||
    { read -rp 'Remove files? ' && [[ $REPLY =~ ^[Yy] ]]; }; then
  rm "$@"
fi
