Skip to content

Commit

Permalink
refactor: improve comments; use ||/&& for one branch if 🎰
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Jan 25, 2024
1 parent 497fac1 commit d48801c
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ PS:
`Shell``Bash`的原因是:

- 目前仍然是主流的`Shell`,并且在不同环境基本上都缺省部署了。
-[`Google``Shell`风格指南](https://zh-google-styleguide.readthedocs.io/en/latest/google-shell-styleguide/background/)中,明确说明了:`Bash`**唯一**被允许执行的`shell`脚本语言。
-[`Google``Shell`风格指南](https://zh-google-styleguide.readthedocs.io/en/latest/google-shell-styleguide/background/)中,明确说到了:`Bash`**唯一**被允许执行的`shell`脚本语言。
- 统一用`Bash`,可以避免差异带来的风险与没有收益的复杂性。
- 有大量的`Shell`实现,`sh``bash``zsh``fish``csh``tcsh``ksh``ash``dash`……
- 不同的`Shell`有各种差异,深坑勿入。
- 统一用`Bash`,可以避免差异带来的风险与没有收益的复杂性。
- 个人系统学习过的是`Bash`,比较理解熟悉。

PS: 虽然交互`Shell`个人已经使用`Zsh` + [`oh-my-zsh`](https://ohmyz.sh/),但在严谨的`Shell`脚本开发时还是使用`Bash`
Expand Down
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
2 changes: 1 addition & 1 deletion bin/show-busy-java-threads
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 d48801c

Please sign in to comment.