-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuntrash.sh
46 lines (36 loc) · 857 Bytes
/
untrash.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
#!/bin/bash
fileName=$1
answer=0
answerToRename=0
[ $# -eq 0 ] && exit
cd ~/
alllog="$(cat ".trash.log")"
echo "" > .trash.log
for i in $alllog
do
if [[ "$i" =~ "$fileName:" ]]
then
echo "Do you want to restore $i? Yes\No"
read answer
if [ $answer = "Yes" ]
then
cd ~/.trash
fileInTrash="$( echo "$i" | cut -d ":" -f 2 )"
mycd="$(echo "$i" | cut -d ":" -f 1 | grep -oP ".*/")"
if [ ! -f $mycd$fileName ]
then
ln -- "$fileInTrash" "$mycd$fileName"
rm -- "$fileInTrash"
else
echo "This file already exists. Do you want to rename it with adding id? Yes/No. Else file will not be restored."
read answerToRename
if [ $answerToRename = "Yes" ]
then ln -- "$fileInTrash" "$mycd$fileName$fileInTrash"
rm -- "$fileInTrash"
fi
fi
fi
cd ~/
else echo "$i" >> .trash.log
fi
done