From 72c39240811f1def43fca71de51566d206f7728d Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Thu, 21 Jan 2021 19:33:10 +0100 Subject: Update 2021-01-21T18:33:10Z --- bin/trash | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'bin/trash') diff --git a/bin/trash b/bin/trash index 5b810c1..4a1de6e 100755 --- a/bin/trash +++ b/bin/trash @@ -1,5 +1,4 @@ #!/bin/sh - set -e TRASH="$HOME/.trash" @@ -34,20 +33,42 @@ yes | $0 --empty EOF } +ask() { + r=$(printf 'yes\nno\n' | MENU_PROMPT="delete $1" menu) + [ "${r}" = "yes" ] && return 0 + return 1 +} + +interactive=${TRASH_ASK:-} +trashrm=${TRASH_RM:-} + case "$1" in -e|--empty) empty_trash exit 0 ;; - -i|--install) + --install) install_auto_empty exit 0 ;; + -i) + interactive=1 + shift ;; -h|--help) echo "usage: trash [-e|--empty] FILE..." exit 1 ;; esac +set -x + # main -for f in "$@"; do +while test $# -gt 0; do + f="$1" ; shift + + [ -n "${interactive}" ] && { ask "$f" || continue; } + echo "+ $(basename "$f")" - mv "$f" "$TRASH/" + if [ -z "${trashrm}" ]; then + rm "$f" + else + mv "$f" "$TRASH/" + fi done -- cgit 1.4.1