-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtra_dl.sh
75 lines (62 loc) · 1.73 KB
/
tra_dl.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/zsh
#
# /
# |_| >_
#
#
# tra.sh: zsh scripts for trash management
# https://marie-helene-burle.netlify.com
# https://github.com/prosoitos
# https://twitter.com/MHBurle
# msb2@sfu.ca
#
# GNU Affero General Public License
#
#
# This script permanently deletes the selected files/directories from the trash
# Multiple files/directories can be selected with <tab>
# Patterns can also be used before selection of all files/directories with <ctrl-o>
# 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
files_path=$trash_path/files
info_path=$trash_path/info
for i in $files_path/*(D)
do
if [[ -d $i ]]
then
dir_or_file="D"
else
dir_or_file=" "
fi
basename=${i#$files_path/}
original_path=$(grep 'Path=' $info_path/$basename.trashinfo |
sed 's/Path=//' |
sed 's/%20/ /g') 2> /dev/null
deletion_time=$(grep 'DeletionDate=' $info_path/$basename.trashinfo |
sed 's/DeletionDate=//' |
sed 's/T/ /') 2> /dev/null
list=$(echo $deletion_time $dir_or_file $original_path \| $basename)
echo $list
done |
sort -r |
fzf -i -e +s -m --bind=ctrl-o:toggle-all --header "Tab: toggle, C-o: toggle-all" |
sed -E 's/.* [D ] (.* \| .*)/\1/' |
while read line
do
# select $basename from selected
basename_selected=$(echo $line | sed -E 's/.* \| (.*)/\1/')
# save stderr in file descriptor 3
exec 3>&2
# do not show stderr (prevents error when metadata is missing)
exec 2> /dev/null
rm -r $files_path/$basename_selected
rm -r $info_path/$basename_selected.trashinfo
# restore stderr to prevent an exit 1
exec 2>&3
done