trash (668B)
1 #!/bin/sh 2 3 # Simple trash management. Files are moved to a directory named with the 4 # current date. 5 6 # Usage: trash [rm FILE(s)|ls|empty] 7 8 # ksh completion 9 # set -A complete_trash_1 rm ls empty 10 11 trashfolder=$XDG_DATA_HOME/mytrash 12 13 usage() { 14 echo "Usage: trash [rm FILES... | ls | empty]" 15 } 16 17 if [ -z "$1" ]; then 18 usage 19 exit 1 20 fi 21 22 case "$1" in 23 empty) 24 # little check 25 if [ -n "$trashfolder" ]; then 26 rm -rf "${trashfolder:?}"/* 27 fi 28 ;; 29 ls) 30 ls "$trashfolder" 31 ;; 32 rm) 33 curdir=$(pwd | sed 's|.*/||') 34 thisfolder="$trashfolder/$(date +'%Y-%m-%d-%s')-$curdir" 35 mkdir -p "$thisfolder" 36 shift 1 37 mv "$@" "$thisfolder" 38 ;; 39 40 *) 41 usage 42 exit 1 43 ;; 44 esac