Skip to content

Commit 88d0d09

Browse files
committed
refactor: improve comments; use ||/&& instead of one branch/one line if 🎰
1 parent 06f4e4b commit 88d0d09

File tree

7 files changed

+10
-18
lines changed

7 files changed

+10
-18
lines changed

bin/a2l

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ while [ $# -gt 0 ]; do
6060
break
6161
;;
6262
-*)
63-
# if unrecognized option, treat it and all follow args as args
63+
# if unrecognized option, treat it and all follow arguments as args
6464
args=(${args[@]:+"${args[@]}"} "$@")
6565
break
6666
;;
6767
*)
68-
# if not option, treat all follow args as args
68+
# if not option, treat all follow arguments as args
6969
args=(${args[@]:+"${args[@]}"} "$@")
7070
break
7171
;;

bin/c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ while [ $# -gt 0 ]; do
111111
usage 2 "unrecognized option '$1'"
112112
;;
113113
*)
114-
# if not option, treat all follow args as command
114+
# if not option, treat all follow arguments as command
115115
target_command=(${target_command[@]:+"${target_command[@]}"} "$@")
116116
break
117117
;;

bin/coat

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ colorLines() {
4444
# How to use `while read` (Bash) to read the last line in a file
4545
# if there’s no newline at the end of the file?
4646
# https://stackoverflow.com/questions/4165135
47-
if [ -n "$line" ]; then
48-
rotateColorPrint "$line"
49-
fi
47+
[ -z "$line" ] || rotateColorPrint "$line"
5048
}
5149

5250
if [ $# == 0 ]; then

bin/cp-into-docker-run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ while (($# > 0)); do
164164
usage 2 "$PROG: unrecognized option '$1'"
165165
;;
166166
*)
167-
# if not option, treat all follow args as command
167+
# if not option, treat all follow arguments as command
168168
args=(${args[@]:+"${args[@]}"} "$@")
169169
break
170170
;;

bin/find-in-jars

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ searchJarFiles() {
349349

350350
total_jar_count=$(printf '%s\n' "$jar_files" | wc -l)
351351
# remove white space, because the `wc -l` output on mac contains white space!
352-
total_jar_count=${total_jar_count//[[:space:]]}
352+
total_jar_count=${total_jar_count//[[:space:]]/}
353353

354354
echo "$total_jar_count"
355355
printf '%s\n' "$jar_files"
@@ -370,13 +370,9 @@ __outputResultOfJarFile() {
370370
# - https://stackoverflow.com/questions/19120263/why-exit-code-141-with-grep-q
371371
# - https://unix.stackexchange.com/questions/305547/broken-pipe-when-grepping-output-but-only-with-i-flag
372372
# - http://www.pixelbeat.org/programming/sigpipe_handling.html
373-
if grep -c "${grep_opt_args[@]}" &>/dev/null; then
374-
matched=true
375-
fi
373+
grep -c "${grep_opt_args[@]}" &>/dev/null && matched=true
376374

377-
if [ "$print_matched_files" != "$matched" ]; then
378-
return
379-
fi
375+
[ "$print_matched_files" != "$matched" ] && return
380376

381377
clearResponsiveMessage
382378
if [ -t 1 ]; then

bin/show-busy-java-threads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ isNaturalNumber "$update_count" || die "update count($update_count) is not a nat
303303
readonly update_count
304304

305305
if [ -n "$pid_list" ]; then
306-
pid_list=${pid_list//[[:space:]]} # delete white space
306+
pid_list=${pid_list//[[:space:]]/} # delete white space
307307
isNaturalNumberList "$pid_list" || die "pid(s)($pid_list) is illegal! example: 42 or 42,99,67"
308308
fi
309309
readonly pid_list

bin/taoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ colorLines() {
4444
# How to use `while read` (Bash) to read the last line in a file
4545
# if there’s no newline at the end of the file?
4646
# https://stackoverflow.com/questions/4165135
47-
if [ -n "$line" ]; then
48-
rotateColorPrint "$line"
49-
fi
47+
[ -z "$line" ] || rotateColorPrint "$line"
5048
}
5149

5250
tac "$@" | colorLines

0 commit comments

Comments
 (0)