From e745ea917296afe95b338d2f4486d2990ae7d3ff Mon Sep 17 00:00:00 2001 From: hugues Date: Tue, 29 May 2007 09:05:14 +0000 Subject: Gestion d'une corbeille... GĂ©ant. :) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://hugues@maison/opt/svn/private/hugues@409 a0e5b806-a6f9-0310-978d-cbce73f8a913 --- 70_Trash.zsh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 70_Trash.zsh (limited to '70_Trash.zsh') 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 +## +## 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' -- cgit v1.2.3