From 88d0d09828441941fccdfadf16933c6208e3cc66 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Thu, 25 Jan 2024 13:38:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20improve=20comments;=20use=20`||/&&`?= =?UTF-8?q?=20instead=20of=20one=20branch/one=20line=20`if`=20=F0=9F=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/a2l | 4 ++-- bin/c | 2 +- bin/coat | 4 +--- bin/cp-into-docker-run | 2 +- bin/find-in-jars | 10 +++------- bin/show-busy-java-threads | 2 +- bin/taoc | 4 +--- 7 files changed, 10 insertions(+), 18 deletions(-) diff --git a/bin/a2l b/bin/a2l index 01612197..81cfcc21 100755 --- a/bin/a2l +++ b/bin/a2l @@ -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 ;; diff --git a/bin/c b/bin/c index d844196a..3aba6a03 100755 --- a/bin/c +++ b/bin/c @@ -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 ;; diff --git a/bin/coat b/bin/coat index 9eff9922..d98d50e0 100755 --- a/bin/coat +++ b/bin/coat @@ -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 diff --git a/bin/cp-into-docker-run b/bin/cp-into-docker-run index d4841e67..c5a0d4e2 100755 --- a/bin/cp-into-docker-run +++ b/bin/cp-into-docker-run @@ -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 ;; diff --git a/bin/find-in-jars b/bin/find-in-jars index fc5e198c..05d23aec 100755 --- a/bin/find-in-jars +++ b/bin/find-in-jars @@ -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" @@ -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 diff --git a/bin/show-busy-java-threads b/bin/show-busy-java-threads index da419b90..27f056ea 100755 --- a/bin/show-busy-java-threads +++ b/bin/show-busy-java-threads @@ -303,7 +303,7 @@ isNaturalNumber "$update_count" || die "update count($update_count) is not a nat readonly update_count if [ -n "$pid_list" ]; then - pid_list=${pid_list//[[:space:]]} # delete white space + pid_list=${pid_list//[[:space:]]/} # delete white space isNaturalNumberList "$pid_list" || die "pid(s)($pid_list) is illegal! example: 42 or 42,99,67" fi readonly pid_list diff --git a/bin/taoc b/bin/taoc index 7a0ebe23..adf7e663 100755 --- a/bin/taoc +++ b/bin/taoc @@ -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