diff options
Diffstat (limited to '70_Trash.zsh')
-rw-r--r-- | 70_Trash.zsh | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/70_Trash.zsh b/70_Trash.zsh new file mode 100644 index 0000000..04aef8a --- /dev/null +++ b/70_Trash.zsh @@ -0,0 +1,62 @@ +#!/bin/zsh +## +## Part of configuration files for Zsh4 +## AUTHOR: Hugues Hiegel <hugues@hiegel.fr> +## +## You are encouraged to use, modify, and redistribute +## these files with or without this notice. +## +## NO WARRANTY PROVIDED, USE AT YOUR OWN RISKS +## + +TRASH=$ZDOTDIR/.trash + +move_to_trash () +{ + FOLDER=$TRASH/$PWD + + for element in $@ + do + if [ -e $element ] + then + echo "Deleting $element..." + mkdir -p $FOLDER/${element:h} + mv -f $element $FOLDER/${element:h}/. + fi + done +} + +list_deleted_elements () +{ + FOLDER=$TRASH/$PWD + + if [ -d $FOLDER ] + then + for element in $(find $FOLDER -maxdepth 1 ! -wholename "$FOLDER" ) + ls -lad $element | sed "s:$FOLDER/::" + else + echo "Nothing found in trash." + fi +} + +undelete_from_trash () +{ + FOLDER=$TRASH/$PWD + + for element in $@ + do + if [ -e $FOLDER/$element ] + then + echo "Getting back $element..." + mkdir -p ${element:h} + mv $FOLDER/$element . + rmdir --ignore-fail-on-non-empty -p $FOLDER + else + echo "Not found in trash: $element" + fi + done +} + +alias delete='move_to_trash' +alias undelete='undelete_from_trash' +alias deleted='list_deleted_elements' |