-
Notifications
You must be signed in to change notification settings - Fork 0
/
trash-recover
executable file
·62 lines (55 loc) · 1.84 KB
/
trash-recover
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
#!/bin/bash
# Perfect trash-cli (https://github.com/andreafrancia/trash-cli)
# Recover files from trash
#
# why dont do this with restore-trash ? because root's file trigger error 'Permission denied'
# zsh completion for it: https://github.com/liangguohuan/ZSH-COMPLETIONS/blob/master/_trash-recover
#
# Tips:
# 1. trigger error 'cannot trash regular file' when trash-put [file]
# trash-put root's file must do it with 'sudo trash-put', if not, it will trigger this error,
# and put the trash.info files to Trash Hub with the current user permission, and the root's file
# you want to trash still in there.
#
# 2. let the sudo dont ask password
#
# sudo visudo
# find # Allow members of group sudo to execute any command,
# replace
# %sudo ALL=(ALL:ALL)
# to
# %sudo ALL=(ALL:ALL) NOPASSWD:NOPASSWD:ALL
# Ctrl + o Save,Ctrl + x Quit
#
# 3. alias trash-cli package commands
# alias trash=sudo trash
# alias trash-put=sudo trash
# alias trash-list=sudo trash-list
#
source "$HOME/CodeHub/SHELL/libs/bootstrap.sh"
HELP_MESSAGE="
desc:
Recover files from trash. Trash file via nautilus as sudo can not recover files via nautilus,
so let the command "trash-recover" help you.
usage:
trash-recover FILE...
"
# must use sudo
# cmn_assert_running_as_root
if [[ -z "$1" || "$1" = "--help" || "$1" = "-h" ]]; then
helpShow
fi
DIR_TRASH="${HOME}/.local/share/Trash"
DIR_TRASHFILES="${DIR_TRASH}/files"
DIR_TRASHINFO="${DIR_TRASH}/info"
for FILE in $*
do
FILE_PATH="${DIR_TRASHFILES}/${FILE}"
if [[ -L "${FILE_PATH}" || -e "${FILE_PATH}" ]]; then
FILE_PATH_TRASHINFO=${DIR_TRASHINFO}/${FILE}.trashinfo
FILE_PATH_RECOVER=$( sudo sed -n "/Path/p" "${FILE_PATH_TRASHINFO}" | sed "s/Path=//" )
sudo mv $FILE_PATH $FILE_PATH_RECOVER
sudo rm $FILE_PATH_TRASHINFO
fi
done
msg_success "Wonderful, it's done."