Skip to content

Commit b3907ec

Browse files
committed
improve find-in-jars
- check dirs - use arithmetic operation
1 parent c2b8b2b commit b3907ec

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

find-in-jars

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ EOF
107107

108108
declare -a args=()
109109
declare -a dirs=()
110-
while [ $# -gt 0 ]; do
110+
while (( $# > 0 )); do
111111
case "$1" in
112112
-d|--dir)
113113
dirs=("${dirs[@]}" "$2")
@@ -170,24 +170,24 @@ regex_mode=${regex_mode:--E}
170170
use_absolute_path=${use_absolute_path:-false}
171171
seperator="${seperator:-!}"
172172

173-
[ "${#args[@]}" -eq 0 ] && usage 1 "No find file pattern!"
174-
[ "${#args[@]}" -gt 1 ] && usage 1 "More than 1 file pattern!"
173+
(( "${#args[@]}" == 0 )) && usage 1 "No find file pattern!"
174+
(( "${#args[@]}" > 1 )) && usage 1 "More than 1 file pattern: ${args[@]}"
175175
readonly pattern="${args[0]}"
176176

177-
# convert dirs to Absolute Path.
178-
$use_absolute_path && {
179-
declare -a tmp_dirs=()
180-
181-
for d in "${dirs[@]}"; do
182-
tmp_dirs=( "${tmp_dirs[@]}" "$(cd "$d" && pwd)" )
183-
done
184-
185-
dirs=( "${tmp_dirs[@]}" )
186-
}
177+
declare -a tmp_dirs=()
178+
for d in "${dirs[@]}"; do
179+
[ -e "$d" ] || die "file $d(specified by option -d) does not exist!"
180+
[ -d "$d" ] || die "file $d(specified by option -d) exists but is not a directory!"
181+
[ -r "$d" ] || die "directory $d(specified by option -d) exists but is not readable!"
182+
# convert dirs to Absolute Path
183+
$use_absolute_path && tmp_dirs=( "${tmp_dirs[@]}" "$(cd "$d" && pwd)" )
184+
done
185+
# set dirs to Absolute Path
186+
$use_absolute_path && dirs=( "${tmp_dirs[@]}" )
187187

188-
# convert to find -iname options
188+
# convert extensions to find -iname options
189189
for e in "${extension[@]}"; do
190-
[ 0 -eq "${#find_iname_options[@]}" ] &&
190+
(( "${#find_iname_options[@]}" == 0 )) &&
191191
find_iname_options=( -iname "*.$e" ) ||
192192
find_iname_options=( "${find_iname_options[@]}" -o -iname "*.$e" )
193193
done

0 commit comments

Comments
 (0)