Skip to content

Commit

Permalink
refactor: use boolean option parse value holder in c, more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Aug 11, 2023
1 parent e1febba commit 3264a17
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions bin/c
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ progVersion() {
################################################################################

quiet=false
eol=-n
keep_eol=false
declare -a args=()
while [ $# -gt 0 ]; do
case "$1" in
-k | --keep-eol)
eol=
keep_eol=true
shift
;;
-q | --quiet)
Expand Down Expand Up @@ -116,7 +116,7 @@ while [ $# -gt 0 ]; do
esac
done

readonly eol quiet args
readonly keep_eol quiet args

################################################################################
# biz logic
Expand All @@ -137,10 +137,15 @@ copy() {
}

catThenCopy() {
local content
local content format
content="$(cat)"
# shellcheck disable=SC2086
echo $eol "$content" | copy
if $keep_eol; then
format='%s\n'
else
format='%s'
fi
# shellcheck disable=SC2059
printf "$format" "$content" | copy
}

teeAndCopy() {
Expand Down

0 comments on commit 3264a17

Please sign in to comment.