-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtra_sd.sh
58 lines (47 loc) · 1.26 KB
/
tra_sd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/zsh
#
# /
# |_| >_
#
#
# tra.sh: zsh scripts for trash management
# https://marie-helene-burle.netlify.com
# https://github.com/prosoitos
# https://twitter.com/MHBurle
#
# GNU Affero General Public License
#
#
# This script sends files/directories to the trash
# It creates the trash if necessary
# and stores the metadata necessary to restore items
# If a file/directory of the same name already exists in trash,
# it creates numbered backups (the backup suffix is automatically
# deleted if the file/directory is restored)
# topdir=$(findmnt -T . -n -o TARGET)
# if [[ $topdir = /home ]]
# then
# trash_path=$HOME/.local/share/Trash
# else
# trash_path=$topdir/.Trash-1000
# fi
trash_path=$HOME/.local/share/Trash
mkdir -p $trash_path/files
mkdir -p $trash_path/info
basename=$(echo $1 | sed -E 's/.*\/(.*)$/\1/')
trash_file=$trash_path/files/$basename
if [[ -e $trash_file ]]
then
i=0
while [[ -e $trash_file~$i ]]
do
let i++
done
basename=$basename~$i
fi
mv $1 $trash_path/files/$basename
echo "[Trash Info]" > $trash_path/info/$basename.trashinfo
echo "Path=$1" >> $trash_path/info/$basename.trashinfo
date +'%FT%T' |
sed 's/^/DeletionDate=/' >> $trash_path/info/$basename.trashinfo