Skip to content

Commit f7b1d13

Browse files
🎨 style: Apply shellcheck recommendations.
1 parent b716720 commit f7b1d13

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

bin/gifify

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@
77
# and
88
# https://github.com/jclem/gifify
99

10-
function log {
10+
log() {
1111
>&2 echo "$@"
1212
}
1313

14-
function debug {
14+
debug() {
1515
if "$verbose" ; then
1616
log "$@"
1717
fi
1818
}
1919

20-
function abort {
20+
abort() {
2121
log "abort: $1"
2222
exit 1
2323
}
2424

25-
function show_help {
25+
show_help() {
2626
log '! No help for the moment :(' ;
27-
log ' > Here is the code of the script. The file is located at '"${BASH_SOURCE}".
27+
log ' > Here is the code of the script. The file is located at '"$0".
2828
if command -v bat > /dev/null ; then
29-
bat "${BASH_SOURCE}"
29+
bat "$0"
3030
elif command -v less > /dev/null ; then
31-
less "${BASH_SOURCE}"
31+
less "$0"
3232
else
33-
cat "${BASH_SOURCE}"
33+
cat "$0"
3434
fi
3535
}
3636

@@ -124,7 +124,7 @@ shift $((OPTIND-1))
124124
use_gifski=true
125125
framerate=
126126

127-
function main {
127+
main() {
128128
checkRequirements
129129
interpret "$@"
130130
encode
@@ -133,14 +133,14 @@ function main {
133133
# This will check both if the required applications are installed, and if they
134134
# are installed with the correct dependencies. For example, to make subtitles
135135
# work, ffmpeg needs to be compiled with `enable-libass`.
136-
function checkRequirements {
136+
checkRequirements() {
137137
checkRequirement ffmpeg -version libass fontconfig
138138
checkRequirement gifsicle -h lossy
139139
checkRequirement convert --version fontconfig
140140
checkRequirement gifski -h
141141
}
142142

143-
function checkRequirement {
143+
checkRequirement() {
144144
cmd="$1" && shift
145145
about="$1" && shift
146146
command -v "$cmd" > /dev/null || notInstalled "$cmd"
@@ -149,15 +149,15 @@ function checkRequirement {
149149
done
150150
}
151151

152-
function notInstalled {
152+
notInstalled() {
153153
abort "Could not find $1. Is it installed?"
154154
}
155155

156-
function missingDependency {
156+
missingDependency() {
157157
abort "$1 needs option $2"
158158
}
159159

160-
function interpret {
160+
interpret() {
161161

162162
# we can only deal with one gif at a time
163163
if [ "$#" -gt 1 ] ; then
@@ -198,7 +198,7 @@ function interpret {
198198
fi
199199
realfps="$(calc 3 100 / "$delay")"
200200
if [ "$realfps" != "$fps" ] ; then
201-
log "Warning: requesting fps=$fps but can only handle integer delay with gifsicle (floor(100 / "$fps") = "$delay"). Will use fps=$realfps to honor speed=$speed."
201+
log "Warning: requesting fps=${fps} but can only handle integer delay with gifsicle (floor(100 / ${fps}) = ${delay}). Will use fps=${realfps} to honor speed=${speed}."
202202
fps="$realfps"
203203
fi
204204
fi
@@ -207,7 +207,7 @@ function interpret {
207207

208208
}
209209

210-
function encode {
210+
encode() {
211211

212212
log "Generating GIF, please wait..."
213213

@@ -224,7 +224,7 @@ function encode {
224224

225225
}
226226

227-
function encode_gifski {
227+
encode_gifski() {
228228

229229
debug "Encoding using gifski"
230230

@@ -252,7 +252,7 @@ function encode_gifski {
252252

253253
}
254254

255-
function encode_default {
255+
encode_default() {
256256

257257
debug "Encoding using convert and gifsicle"
258258

@@ -274,7 +274,7 @@ function encode_default {
274274

275275
}
276276

277-
function computeFFmpegArgs {
277+
computeFFmpegArgs() {
278278
# FFmpeg options
279279
# https://www.ffmpeg.org/ffmpeg.html#Options
280280
printf '%s\0%s\0' -loglevel panic
@@ -338,7 +338,7 @@ function computeFFmpegArgs {
338338

339339
}
340340

341-
function computeConvertArgs {
341+
computeConvertArgs() {
342342
# Convert options
343343
# http://www.imagemagick.rg/script/convert.php#options
344344
printf '%s\0' -
@@ -357,7 +357,7 @@ function computeConvertArgs {
357357
printf '%s\0' gif:-
358358
}
359359

360-
function computeGifsicleArgs {
360+
computeGifsicleArgs() {
361361
# Gifsicle options
362362
# http://www.lcdf.org/gifsicle/man.html
363363

@@ -374,7 +374,7 @@ function computeGifsicleArgs {
374374
fi
375375
}
376376

377-
function computeGifskiArgs {
377+
computeGifskiArgs() {
378378

379379
printf '%s\0%s\0' --output "$output"
380380
printf '%s\0%s\0' --fps "$fps" # supports fractional fps
@@ -401,17 +401,17 @@ function computeGifskiArgs {
401401
find "$1/frames" -type f -print0 | sort -z -n $ordering
402402
}
403403

404-
function calc {
404+
calc() {
405405
scale="$1" && shift
406-
result="$(printf -- "scale=$scale;($*)/1\n" | bc | tr -d '\\\n')"
407-
if grep -q '[.]' <<< "$result" ; then
406+
result="$(printf '%s\n' "scale=$scale;($*)/1" | bc | tr -d '\\\n')"
407+
if printf '%s' "$result" | grep -q '[.]' ; then
408408
# improve the output for decimal numbers
409-
printf -- "$result" |
409+
printf '%s\n' "$result" |
410410
sed -e 's/^\./0./' `# add "0" for cases like ".5"` \
411411
-e 's/^-\./-0./' `# add "0" for cases like "-.5"`\
412412
-e 's/0*$//;s/\.$//' # remove trailing zeros
413413
else
414-
printf -- "$result"
414+
printf '%s\n' "$result"
415415
fi
416416
}
417417

0 commit comments

Comments
 (0)