-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.sh
executable file
·57 lines (54 loc) · 1.48 KB
/
remove.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
#!/bin/sh
scriptName=${0##*/}
ask=1
if [ $# = 0 ] ; then
echo "Wrapper script for the dangerous 'rm -rf'"
echo "Usage : $scriptName [folder to delete]"
exit 0
fi
echo "$scriptName : Delete following files/folders?"
printf "$(tput setaf 6) %s\n" "$@"
tput sgr 0
for p in "$@" ; do
if [ "${p:0}" = '/' ] ; then
echo "$scriptName : Too Dangerous!!! (trying to delete a root level folder)"
echo "$scriptName : aborted..."
exit 1
elif [ "$p" = '..' -o "$p" = '.' ] ; then
echo "$scriptName : Too Dangerous!!! (trying to delete \"$p\")"
echo "$scriptName : aborted..."
exit 1
fi
if [ -d "$p" ] ; then
type='(folder)'
elif [ -f "$p" ] ; then
type='(file)'
else
type='(other)'
fi
if [ $ask = 1 ] ; then
printf "$scriptName : Delete $p $type [y, n (default), c=cancel, all]? "
#printf "$(tput setaf 6) %s\n" "$@"
#tput sgr 0
ok=no
read ok
fi
if [ "$ok" = 'all' ] ; then
ask=0
ok='y'
fi
if [ "${ok:0}" = 'y' ] ; then
if [ -f "$p" ] ; then
rm -f "$p"
echo "$scriptName : \"$p\" (file) deleted..."
elif [ -d "$p" ] ; then
rm -rf "$p"
echo "$scriptName : \"$p\" (folder) deleted..."
else
echo "$scriptName : \"$p\" not found..."
fi
elif [ "${ok:0}" = 'c' ] ; then
echo "$scriptName : cancelled..."
exit 1
fi
done