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 b92cd00
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 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 @@ -139,8 +139,10 @@ copy() {
catThenCopy() {
local content
content="$(cat)"
# shellcheck disable=SC2086
echo $eol "$content" | copy
{
printf %s "$content"
$keep_eol && echo
} | copy
}

teeAndCopy() {
Expand Down

0 comments on commit b92cd00

Please sign in to comment.