-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.bash
117 lines (89 loc) · 1.93 KB
/
test.bash
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
set -Ceu
readonly ORIGIN=$(pwd)
readonly CMD_DIR="$(realpath $(dirname ${BASH_SOURCE[0]}))"
readonly RM_CMD="${CMD_DIR}/rm-alternative.bash"
readonly WORKDIR="${CMD_DIR}/workdir"
[[ -d $WORKDIR ]] || mkdir $WORKDIR
declare -x RM_ALT_TRASH="${WORKDIR}/trash"
declare -x RM_ALT_HIST="${RM_ALT_TRASH}/.moved_hist"
function postprocess() {
[[ -d "${WORKDIR}" ]] && $(/bin/rm -rf "${WORKDIR}")
$(cd $ORIGIN)
}
trap postprocess EXIT
function e_header() {
printf "\n \033[37;1m%s\033[m\n" "$*"
}
function e_arrow() {
printf " \033[37;1m%s\033[m\n" "➜ $*"
}
function e_done() {
printf " \033[37;1m%s\033[m...\033[32mOK\033[m\n" "✔ $*"
}
function check_safe_rm() {
e_header "$FUNCNAME"
cd $WORKDIR
cmd="mkdir test-dir"
e_arrow $cmd &&
$(eval $cmd) &&
e_done &&
cmd="${RM_CMD} test-dir" &&
e_arrow $cmd &&
$(eval $cmd) &&
e_done &&
cmd="ls ${RM_ALT_TRASH}/test-dir" &&
e_arrow $cmd &&
eval $cmd &&
e_done &&
e_done "$FUNCNAME"
}
function check_restore() {
e_header "$FUNCNAME"
cd $WORKDIR
cmd="mkdir test-dir"
e_arrow $cmd &&
$(eval $cmd) &&
e_done &&
cmd="${RM_CMD} test-dir" &&
e_arrow $cmd &&
$(eval $cmd) &&
e_done &&
cmd="${RM_CMD} --restore" &&
e_arrow $cmd &&
eval $cmd &&
e_done &&
cmd="ls test-dir" &&
e_arrow $cmd &&
eval $cmd &&
e_done &&
e_done "$FUNCNAME"
/bin/rm -r test-dir
}
function is_not_exist() {
if [[ -e $1 ]]; then
return 1
else
return 0
fi
}
function check_delete() {
e_header "$FUNCNAME"
cd $WORKDIR
cmd="mkdir test-dir"
e_arrow $cmd &&
$(eval $cmd) &&
e_done &&
cmd="${RM_CMD} -d test-dir" &&
e_arrow $cmd &&
$(eval $cmd) &&
e_done &&
cmd="is_not_exist test-dir" &&
e_arrow $cmd &&
eval $cmd &&
e_done &&
e_done "$FUNCNAME"
}
check_safe_rm
check_delete
check_restore