diff options
Diffstat (limited to 'bin/trash')
| -rwxr-xr-x | bin/trash | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/bin/trash b/bin/trash deleted file mode 100755 index 5a040cb..0000000 --- a/bin/trash +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -rmbin=/bin/rm - -TRASH="$HOME/.trash" -if [ ! -d "$TRASH" ]; then - mkdir -p "$TRASH" -fi - -ls_trash() { - # shellcheck disable=SC2068 - fd -H . "${TRASH:?}" $@ -} - -empty_trash() { - if [ ! -d "$TRASH" ] || [ -z "$(ls_trash)" ]; then - exit 0 - fi - echo " +++ trash +++" - ls_trash - read -r yn - if [ "$yn" = "y" ]; then - printf ' +++ removing everything under %s (%d)... ' "$TRASH" "$(fd . "${TRASH:?}" | wc -l)" - ls_trash -x $rmbin -r - echo 'done.' - fi -} - -install_auto_empty() { - case "$SHELL" in - *zsh) logoutfile="$ZDOTDIR/.zlogout" ;; - *bash) logoutfile="$HOME/.bash_logout" ;; - *) - echo "unknown shell $SHELL" 1>&2 - exit 1 - ;; - esac - cat >"$logoutfile" <<EOF -# auto-empty-trash routine of $0 -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 - ;; - --install) - install_auto_empty - exit 0 - ;; - -i) - interactive=1 - shift - ;; - -h | --help) - echo "usage: trash [-e|--empty] FILE..." - exit 1 - ;; -esac - -# main -while test $# -gt 0; do - f="$1" - shift - - [ -n "${interactive}" ] && { ask "$f" || continue; } - - echo "+ $(basename "$f")" - if [ -n "${trashrm}" ]; then - [ -d "$f" ] && $rmbin -r "$f" || $rmbin "$f" - else - mv "$f" "$TRASH/" - fi -done |