-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove-colons.sh
executable file
·110 lines (92 loc) · 2.05 KB
/
remove-colons.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
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
#!/usr/bin/env bash
LANGUAGE=en_US.UTF-8
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
d_flag=''
v_flag=''
print_usage() {
printf "Usage: -d make changes, -v verbose, -h help"
}
while getopts 'dvh' flag; do
case "${flag}" in
d) d_flag=true
shift 1 ;;
v) v_flag=true
shift 1 ;;
h | *) print_usage
exit 1 ;;
esac
done
repl=$(printf '\uf022')
# args=("$@")
# if [[ ${#args[@]} -gt 0 ]];then
# echo "args ${args[@]}"
# if [[ -d "${args[0]}" ]];then
# if [ "$d_flag" = true ];then
# echo "repairing ${args[0]}"
# mv -- "${args[0]}" "${args[0]//:/$repl}"
# else
# echo "pre ${args[0]} post ${args[0]//:/$repl}"
# fi
# exit 0
# fi
# fi
chars='[:]'
count=0
rgx="*${chars}*"
find_cmd=(
find
.
-depth
# -type f
-name "$rgx"
-print0 # delimit output with NUL characters
)
# turn on extended glob syntax
shopt -s extglob
while IFS= read -r -d '' source; do
if [[ "$source" != "." ]]; then
target=${source##*/}
path=${source%/*}
dest="${path}/${target//:/$repl}"
((count++))
if [ "$d_flag" = true ];then
if [ "$v_flag" = true ];then
echo "Changing $source to $dest"
echo
fi
mv -- "${source}" "${dest}"
else
if [ "$v_flag" = true ];then
echo "source ${source}"
echo "dest ${dest}"
echo
fi
fi
fi
done < <("${find_cmd[@]}")
source=$(pwd)
target=${source##*/}
path=${source%/*}
dest="${path}/${target//:/$repl}"
echo "source ${source}"
echo "dest ${dest}"
echo
if [ "$d_flag" = true ];then
if [ "$v_flag" = true ];then
echo "Changing $source to $dest"
echo
fi
mv -- "${source}" "${dest}"
else
if [ "$v_flag" = true ];then
echo "source ${source}"
echo "dest ${dest}"
echo
fi
fi
if [ "$d_flag" = true ];then
echo "Repaired ${count} instances"
else
echo "Found ${count} instances"
fi