summary refs log tree commit diff
path: root/bin/trash
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2021-01-21 19:33:10 +0100
committerRobert Günzler <r@gnzler.io>2021-01-21 19:40:20 +0100
commit72c39240811f1def43fca71de51566d206f7728d (patch)
treea33aa1331fc55b587a243f64ef94d781df40a8ae /bin/trash
parent0762801ed9627021e732cdeb225a737f44e3df42 (diff)
Update 2021-01-21T18:33:10Z
Diffstat (limited to 'bin/trash')
-rwxr-xr-xbin/trash29
1 files changed, 25 insertions, 4 deletions
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