Skip to content

Commit 84b6218

Browse files
committed
refactor: use boolean option parse value holder in c; reanme var. more readable
1 parent e1febba commit 84b6218

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

bin/c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ progVersion() {
8282
################################################################################
8383

8484
quiet=false
85-
eol=-n
86-
declare -a args=()
85+
keep_eol=false
86+
declare -a target_command=()
8787
while [ $# -gt 0 ]; do
8888
case "$1" in
8989
-k | --keep-eol)
90-
eol=
90+
keep_eol=true
9191
shift
9292
;;
9393
-q | --quiet)
@@ -102,21 +102,21 @@ while [ $# -gt 0 ]; do
102102
;;
103103
--)
104104
shift
105-
args=(${args[@]:+"${args[@]}"} "$@")
105+
target_command=(${target_command[@]:+"${target_command[@]}"} "$@")
106106
break
107107
;;
108108
-*)
109109
usage 2 "${PROG}: unrecognized option '$1'"
110110
;;
111111
*)
112112
# if not option, treat all follow args as command
113-
args=(${args[@]:+"${args[@]}"} "$@")
113+
target_command=(${target_command[@]:+"${target_command[@]}"} "$@")
114114
break
115115
;;
116116
esac
117117
done
118118

119-
readonly eol quiet args
119+
readonly keep_eol quiet target_command
120120

121121
################################################################################
122122
# biz logic
@@ -139,8 +139,10 @@ copy() {
139139
catThenCopy() {
140140
local content
141141
content="$(cat)"
142-
# shellcheck disable=SC2086
143-
echo $eol "$content" | copy
142+
{
143+
printf %s "$content"
144+
$keep_eol && echo
145+
} | copy
144146
}
145147

146148
teeAndCopy() {
@@ -151,8 +153,8 @@ teeAndCopy() {
151153
fi
152154
}
153155

154-
if [ ${#args[@]} -eq 0 ]; then
156+
if [ ${#target_command[@]} -eq 0 ]; then
155157
teeAndCopy
156158
else
157-
"${args[@]}" | teeAndCopy
159+
"${target_command[@]}" | teeAndCopy
158160
fi

0 commit comments

Comments
 (0)