#!/usr/bin/env sh

set -o errexit
set -o nounset

case $(uname) in
  Darwin)
    # heavily modified from [this script][0], licensed under the MIT License.
    # [0]: https://github.com/morgant/tools-osx/blob/71c2db389c48cee8d03931eeb083cfc68158f7ed/src/trash#L293-L311
    for arg in "$@"; do
      file="$(realpath "${arg}")"
      /usr/bin/osascript -e "tell application \"Finder\" to delete POSIX file \"${file}\"" >/dev/null
    done
    ;;
  *)
    # gio trash "$@"
    command -v trash-put >/dev/null 2>&1 \
      && trash-put "$@"
    ;;
esac
