Skip to content

Commit 479a298

Browse files
committed
refactor: use $(fn) instead of backtick calls
1 parent 5aaf104 commit 479a298

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

please

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ set -e
1212

1313
declare -A EVENTS
1414

15-
FULL=`readlink -f $0` # fullpath
16-
PLIZ=`basename $0` # name
15+
FULL=$(readlink -f $0) # fullpath
16+
PLIZ=$(basename $0) # name
1717

1818
line() { echo -e "\e[${3:-0};$2m$1\e[0m"; if [[ "$4" != "" ]]; then exit $4; fi }
1919
error() { line "$1" 31 0 $2; }
@@ -26,10 +26,10 @@ qgit() { git "$@" &>> $TMP_LOG; }
2626
# github api
2727
github()
2828
{
29-
RESP=`bash -c "curl --silent -H 'Authorization: token $GH_AUTH_TOKEN' $@"`
29+
RESP=$(bash -c "curl --silent -H 'Authorization: token $GH_AUTH_TOKEN' $@")
3030
echo "$RESP" >> ${TMP_LOG}
3131

32-
ERROR=`echo $RESP | jq -r '.message?'`
32+
ERROR=$(echo $RESP | jq -r '.message?')
3333
[[ $ERROR ]] && [[ "null" != "$ERROR" ]] && error "Github: $ERROR" 1
3434

3535
echo "$RESP"
@@ -39,7 +39,7 @@ github()
3939
usage()
4040
{
4141
cat << USAGE
42-
$PLIZ $(info `version`) | $(ok "(c) Jitendra Adhikari") | $PLIZ is semver release made easy.
42+
$PLIZ $(info $(version)) | $(ok "(c) Jitendra Adhikari") | $PLIZ is semver release made easy.
4343
4444
$(ok Usage:) $PLIZ [command|scope] [--options]
4545
@@ -104,9 +104,9 @@ organize-commits() # $1 = diff_range, $2 = commit_types_csv
104104
if [[ "$scope" != "" ]]; then scope="**${scope^}**: "; fi
105105
CHANGELOG[$type]="${CHANGELOG[$type]}- ${scope}${subject^}\n"
106106
fi
107-
done <<< `git log $1 --no-merges --oneline --pretty="$GCFMT" --grep "\[skip" --grep "skip\]" --grep "StyleCI" --invert-grep`
107+
done <<< $(git log $1 --no-merges --oneline --pretty="$GCFMT" --grep "\[skip" --grep "skip\]" --grep "StyleCI" --invert-grep)
108108

109-
ORGANIZED="" TYPES=(`echo ${2:-feat,fix,refactor,revert,perf,chore,infra,docs,build} | tr ',' '\n'`)
109+
ORGANIZED="" TYPES=($(echo ${2:-feat,fix,refactor,revert,perf,chore,infra,docs,build} | tr ',' '\n'))
110110
for TYPE in ${TYPES[@]}; do
111111
if [[ "${CHANGELOG[$TYPE]}" != "" ]]; then
112112
ORGANIZED="$ORGANIZED### ${LABELS[$TYPE]}\n${CHANGELOG[$TYPE]}\n"
@@ -118,7 +118,7 @@ organize-commits() # $1 = diff_range, $2 = commit_types_csv
118118
# update please
119119
update()
120120
{
121-
NEWVER=`curl -sSL https://raw.githubusercontent.com/adhocore/please/master/VERSION`
121+
NEWVER=$(curl -sSL https://raw.githubusercontent.com/adhocore/please/master/VERSION)
122122
[[ "v$NEWVER" == "$(version)" ]] && ok "Already latest version" 0
123123

124124
info "Updating $PLIZ ..."
@@ -131,7 +131,7 @@ version() { echo v0.10.3; }
131131
# get box.phar path
132132
get-box()
133133
{
134-
case `php -r "echo substr(phpversion(), 0, 3);"` in
134+
case $(php -r "echo substr(phpversion(), 0, 3);") in
135135
7.2 | 7.3 | 7.4) BOX_VER=3.8.0 ;;
136136
7.1) BOX_VER=3.7.0 ;;
137137
7.0 | 5.6 | 5.5 | 5.4 | 5.3) BOX_VER=2.7.5 ;;
@@ -146,38 +146,38 @@ get-box()
146146
fi
147147
fi
148148

149-
echo `realpath ~/box.$BOX_VER.phar`
149+
echo $(realpath ~/box.$BOX_VER.phar)
150150
}
151151

152152
# publish phar
153153
publish-phar()
154154
{
155-
PBIN=`cat composer.json | jq -r '.bin[0]?'`
155+
PBIN=$(cat composer.json | jq -r '.bin[0]?')
156156
if [ "null" == "$PBIN" ]; then
157157
info "Check ${TMP_LOG} for logs" && error "Check bin value in composer.json" 1
158158
fi
159159

160160
trigger before-phar
161161
info "Compiling phar ..."
162-
php `get-box` compile >> ${TMP_LOG}
162+
php $(get-box) compile >> ${TMP_LOG}
163163
ok
164164

165-
PHAR_FILE=`realpath $PBIN.phar` NAME=`basename $PHAR_FILE`
165+
PHAR_FILE=$(realpath $PBIN.phar) NAME=$(basename $PHAR_FILE)
166166
info "Publishing phar ..."
167167

168-
SIZE=`github \
168+
SIZE=$(github \
169169
"-H 'Content-Type: application/octet-stream' \
170170
--data-binary @$PHAR_FILE \
171171
https://uploads.$GH_REPO/releases/$LAST_RELEASE_ID/assets?name=$NAME" \
172-
| jq -r '.size'`
172+
| jq -r '.size')
173173
ok
174174
info "[OK] $NAME $SIZE bytes"
175175
}
176176

177177
# publish npm
178178
publish-npm()
179179
{
180-
PKG=`cat ./package.json` PVT=`echo $PKG | jq -r '.private?'`
180+
PKG=$(cat ./package.json) PVT=$(echo $PKG | jq -r '.private?')
181181
echo $PKG | jq ".version = \"$NEXT_VERSION\"" > ./package.json
182182
qgit add ./package.json && GPUSH=1
183183

@@ -207,7 +207,7 @@ trigger() # $1 = event
207207
}
208208

209209
GCFMT="%s (%an)" # git commit log format
210-
REPO=`git config --get remote.origin.url | sed -e 's/git@github.com://;s/https:\/\/github.com\///;s/.git//'`
210+
REPO=$(git config --get remote.origin.url | sed -e 's/git@github.com://;s/https:\/\/github.com\///;s/.git//')
211211

212212
# load events
213213
[[ -f ./please.json ]] && eval $(cat ./please.json | jq -r 'to_entries|map("EVENTS[\(.key)]=\"\(.value)\"")|.[]')
@@ -242,7 +242,7 @@ VFILE=${VFILE:-0} # create version file
242242
CHLOG=${CHLOG:-0} # create changelog file
243243
YES=${YES:-0} # assume yes
244244

245-
GH_REPO="github.com/repos/$REPO" TMP_LOG=`mktemp -t PLZ.XXXXXXXXXX`
245+
GH_REPO="github.com/repos/$REPO" TMP_LOG=$(mktemp -t PLZ.XXXXXXXXXX)
246246
ok "Repository $REPO" && info "Log file $TMP_LOG"
247247

248248
DEPLOY_BRANCH="${DEPLOY_BRANCH:-master}"
@@ -258,14 +258,14 @@ else
258258
fi
259259

260260
info "Getting latest releases ..."
261-
VERSION=`github "https://api.$GH_REPO/releases?per_page=1" | jq -r '.[0]?.tag_name?'`
261+
VERSION=$(github "https://api.$GH_REPO/releases?per_page=1" | jq -r '.[0]?.tag_name?')
262262
RANGE="$VERSION..HEAD"
263263

264264
[[ "null" == "$VERSION" ]] && { VERSION="0.0.0" RANGE=""; }
265265
ok " Done [$VERSION]"
266266

267267
info "Collecting commits ..."
268-
COMMITS=`organize-commits "$RANGE" "$TYPES"`
268+
COMMITS=$(organize-commits "$RANGE" "$TYPES")
269269
ok
270270

271271
[[ $COMMITS ]] || error "Nothing to release" 0
@@ -275,19 +275,19 @@ echo $COMMITS >> $TMP_LOG
275275
# determine next version
276276
info "Bumping version ..."
277277
if [[ "" = "$NEXT_VERSION" ]]; then
278-
FEAT=`git log $RANGE --oneline --pretty="%s" | grep -P '^feat' || echo ""`
278+
FEAT=$(git log $RANGE --oneline --pretty="%s" | grep -P '^feat' || echo "")
279279
if [[ $MAJOR -eq 1 ]]; then
280280
V=""
281281
if [[ $VERSION == v* ]]; then
282282
V="v" VERSION="${VERSION//v/}"
283283
fi
284-
NEXT_VERSION=`echo $VERSION | (IFS=".$IFS"; read a b c && echo $V$((a + 1)).0.0)`
284+
NEXT_VERSION=$(echo $VERSION | (IFS=".$IFS"; read a b c && echo $V$((a + 1)).0.0))
285285
elif [[ $MINOR -eq 1 ]]; then
286-
NEXT_VERSION=`echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$((b + 1)).0)`
286+
NEXT_VERSION=$(echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$((b + 1)).0))
287287
elif [[ "" != "$FEAT" ]]; then
288-
NEXT_VERSION=`echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$((b + 1)).0)`
288+
NEXT_VERSION=$(echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$((b + 1)).0))
289289
else
290-
NEXT_VERSION=`echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$b.$((c + 1)))`
290+
NEXT_VERSION=$(echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$b.$((c + 1))))
291291
fi
292292
fi
293293
ok " Done [$NEXT_VERSION]"
@@ -333,12 +333,12 @@ fi
333333
# github release
334334
trigger before-vcs
335335
info "Releasing $NEXT_VERSION ..."
336-
COMMITS=`printf %s "$COMMITS"`
337-
LAST_RELEASE_ID=`curl --silent -H "Authorization: token $GH_AUTH_TOKEN" \
336+
COMMITS=$(printf %s "$COMMITS")
337+
LAST_RELEASE_ID=$(curl --silent -H "Authorization: token $GH_AUTH_TOKEN" \
338338
-H 'Content-Type: application/json' \
339339
-d "{\"tag_name\":\"$NEXT_VERSION\",\"name\":\"Version $NEXT_VERSION\",\"body\":\"$COMMITS\"}" \
340340
https://api.$GH_REPO/releases \
341-
| jq -r '.id?'`
341+
| jq -r '.id?')
342342

343343
if [ "null" == "${LAST_RELEASE_ID:-null}" ]; then
344344
error "Something went wrong" && info "Check $TMP_LOG for logs" 1

0 commit comments

Comments
 (0)