-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhide.sh
71 lines (59 loc) · 1.38 KB
/
hide.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
#!/usr/bin/bash -e
#####
# A simple bash script to hide files or directories by just adding a dot in the beginning of that file or directory
#####
target=""
status=0
_help(){
echo "
Usage: $0 FILE_OR_DIRECTORY_TO_HIDE
Hide files or directories by just adding a dot in the beginning of that file or directory.
Exit status:
0 if OK,
1 if minor problems.
"
}
check_target(){
# check if needed file or directory exists
if ! [ -f ${target} ] && ! [ -d ${target} ]; then
echo "$0: --> '${target}' No such file or directory"
return 1
else
return 0
fi
}
hide(){
if [[ ${target} == */* ]] || [[ ${target} == *//* ]] && [[ ${target: -1} != "/" ]]; then
_target=$target
temp=${target%/*}/
target=${target##*/}
# check if needed file/dir is already not hidden
if [[ ${target:0:1} == "." ]]; then status=0
else
mv ${_target} ${temp}.${target##*/} >>/dev/null 2>&1
status=$?
fi
else
if [[ ${target:0:1} == "." ]]; then status=0
else
mv ${target} .${target} >>/dev/null 2>&1
status=$?
fi
fi
}
# START
if [ "$#" -eq 0 ]; then
_help
exit 1
else
i=1
for i in ${@:1}; do
target=$i
check_target
if [[ $? -eq 0 ]];then hide
else status=$?
fi
done
fi
# FINISH
exit $status