Skip to content

Commit

Permalink
refactor: improve comments; use ||/&& instead of one branch/one lin…
Browse files Browse the repository at this point in the history
…e `if` 🎰
  • Loading branch information
oldratlee committed Feb 18, 2024
1 parent c678e28 commit fedbd4f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 17 deletions.
4 changes: 2 additions & 2 deletions bin/a2l
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ while [ $# -gt 0 ]; do
break
;;
-*)
# if unrecognized option, treat it and all follow args as args
# if unrecognized option, treat it and all follow arguments as args
args=(${args[@]:+"${args[@]}"} "$@")
break
;;
*)
# if not option, treat all follow args as args
# if not option, treat all follow arguments as args
args=(${args[@]:+"${args[@]}"} "$@")
break
;;
Expand Down
2 changes: 1 addition & 1 deletion bin/c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ while [ $# -gt 0 ]; do
usage 2 "unrecognized option '$1'"
;;
*)
# if not option, treat all follow args as command
# if not option, treat all follow arguments as command
target_command=(${target_command[@]:+"${target_command[@]}"} "$@")
break
;;
Expand Down
4 changes: 1 addition & 3 deletions bin/coat
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ colorLines() {
# How to use `while read` (Bash) to read the last line in a file
# if there’s no newline at the end of the file?
# https://stackoverflow.com/questions/4165135
if [ -n "$line" ]; then
rotateColorPrint "$line"
fi
[ -z "$line" ] || rotateColorPrint "$line"
}

if [ $# == 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion bin/cp-into-docker-run
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ while (($# > 0)); do
usage 2 "$PROG: unrecognized option '$1'"
;;
*)
# if not option, treat all follow args as command
# if not option, treat all follow arguments as command
args=(${args[@]:+"${args[@]}"} "$@")
break
;;
Expand Down
10 changes: 3 additions & 7 deletions bin/find-in-jars
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ searchJarFiles() {

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

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

if [ "$print_matched_files" != "$matched" ]; then
return
fi
[ "$print_matched_files" != "$matched" ] && return

clearResponsiveMessage
if [ -t 1 ]; then
Expand Down
4 changes: 1 addition & 3 deletions bin/taoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ colorLines() {
# How to use `while read` (Bash) to read the last line in a file
# if there’s no newline at the end of the file?
# https://stackoverflow.com/questions/4165135
if [ -n "$line" ]; then
rotateColorPrint "$line"
fi
[ -z "$line" ] || rotateColorPrint "$line"
}

tac "$@" | colorLines

0 comments on commit fedbd4f

Please sign in to comment.