Skip to content

Commit 6f1ac07

Browse files
replace arithmetic comparisons of the form [[ ... ]] with (( ... ))
1 parent 670d62f commit 6f1ac07

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

batrg

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ for ((i=1,ie=$#batrg_args; i <= ie; ++i)) ; do
264264
esac
265265
done
266266

267-
if [[ $positional_pattern -eq 1 ]] && [[ $# -eq 0 ]]; then
267+
if (( $positional_pattern == 1 && $# == 0 )); then
268268
help
269269
exit 2
270270
fi
@@ -279,41 +279,41 @@ else
279279
terminal_width=
280280
fi
281281

282-
if [[ $#file_separator -eq 1 ]]; then
282+
if (( $#file_separator == 1 )); then
283283
if [[ -n $terminal_width ]]; then
284284
file_separator=${${(l:$terminal_width:: :)''}// /"$file_separator"}$'\n'
285285
else
286286
file_separator=
287287
fi
288288
fi
289289

290-
if [[ $style -eq 0 ]] && [[ -z $BAT_STYLE ]]; then
291-
if [[ $snip -eq 2 ]]; then
292-
if [[ $ctx_after -eq 0 ]] && [[ $ctx_before -eq 0 ]]; then
290+
if (( $style == 0 )) && [[ -z $BAT_STYLE ]]; then
291+
if (( $snip == 2 )); then
292+
if (( $ctx_after == 0 && $ctx_before == 0 )); then
293293
snip=0
294294
else
295295
# --style=snip since bat-0.12
296296
bat_version=$($=bat_engine --version)
297297
setopt extendedglob
298298
if [[ $bat_version = 'bat '(#b)(<0-9>##).(<0-9>##)* ]] &&
299299
[[ ${bat_version[$mbegin[1],$mend[1]]} = 0 ]] &&
300-
[[ ${bat_version[$mbegin[2],$mend[2]]} -lt 12 ]] ;
300+
(( ${bat_version[$mbegin[2],$mend[2]]} < 12 )) ;
301301
then
302302
snip=0
303303
fi
304304
setopt noextendedglob
305305
fi
306306
fi
307307

308-
if [[ $snip -eq 0 ]]; then
308+
if (( $snip == 0 )); then
309309
bat_args+=(--style=numbers,header)
310310
else
311311
bat_args+=(--style=numbers,header,snip)
312312
fi
313313
fi
314314

315-
if [[ $highlight -eq 2 ]]; then
316-
if [[ $ctx_after -eq 0 ]] && [[ $ctx_before -eq 0 ]]; then
315+
if (( $highlight == 2 )); then
316+
if (( $ctx_after == 0 && $ctx_before == 0 )); then
317317
highlight=0
318318
else
319319
highlight=1
@@ -324,7 +324,7 @@ fi
324324
temp_files=()
325325
remove_temps()
326326
{
327-
if [[ $#temp_files -ne 0 ]]; then
327+
if (( $#temp_files != 0 )); then
328328
rm -- $temp_files
329329
fi
330330
}
@@ -340,7 +340,7 @@ if [[ $@[$i] = '--' ]] ; then
340340
rg_args+=(--)
341341
fi
342342

343-
if [[ $positional_pattern -eq 1 ]]; then
343+
if (( $positional_pattern == 1 )); then
344344
rg_args+=($@[$file_index])
345345
((++file_index))
346346
fi
@@ -358,20 +358,20 @@ for ((i=1,ie=$#files; i <= $ie; ++i)) ; do
358358
<$files[$i] >$tmp
359359
fi
360360
files[$i]=$tmp
361-
elif [[ $files[$i] = '--' ]] && [[ $has_sep -eq 0 ]]; then
361+
elif [[ $files[$i] = '--' ]] && (( $has_sep == 0 )); then
362362
((--nb_files))
363363
has_sep=1
364364
fi
365365
((++nb_files))
366366
done
367367

368-
if [[ $nb_files -eq 0 ]] && [[ ! -t 0 ]]; then
368+
if (( $nb_files == 0 )) && [[ ! -t 0 ]]; then
369369
tmp=${BATRG_PREFIX}stdin
370370
temp_files+=($tmp)
371371
files+=($tmp)
372372
nb_files=1
373373
<&0 >$tmp
374-
elif [[ $nb_files -eq 1 ]] && [[ -d $files ]] ; then
374+
elif (( $nb_files == 1 )) && [[ -d $files ]] ; then
375375
nb_files=2 # assume there is more than 1 file
376376
fi
377377

@@ -393,9 +393,9 @@ main()
393393

394394
run_bat()
395395
{
396-
[[ $found -ne 0 ]] && echo -nE $file_separator
396+
(( $found != 0 )) && echo -nE $file_separator
397397
first_line=$(($first_line-$ctx_before))
398-
[[ $first_line -gt 0 ]] || first_line=
398+
(( $first_line > 0 )) || first_line=
399399
curr_bat_args[1]='--line-range='$first_line':'$(($prev_line+$ctx_after))
400400
$=bat_engine $bat_args $curr_bat_args -- $filename
401401
found=2
@@ -421,24 +421,24 @@ main()
421421
break
422422
fi
423423

424-
if [[ $(($prev_line+1)) -ne $line ]]; then
424+
if (( $prev_line+1 != $line )); then
425425
first_line=$(($first_line-$ctx_before))
426-
[[ $first_line -gt 0 ]] || first_line=
426+
(( $first_line > 0 )) || first_line=
427427
curr_bat_args+=( '--line-range='$first_line':'$(($prev_line+$ctx_after)) )
428428
first_line=$line
429429
fi
430430

431-
if [[ $highlight -eq 1 ]]; then
431+
if (( $highlight == 1 )); then
432432
curr_bat_args+=(--highlight-line=$line)
433433
fi
434434

435435
prev_line=$line
436436
done
437437
done
438438

439-
if [[ $prev_line -ne -1 ]]; then
439+
if (( $prev_line != -1 )); then
440440
run_bat
441-
[[ $file_separator_wrap -eq 1 ]] && echo -nE $file_separator
441+
(( $file_separator_wrap == 1 )) && echo -nE $file_separator
442442
fi
443443
}
444444

@@ -448,7 +448,7 @@ main()
448448
main_with_pager()
449449
{
450450
if [[ -t 1 ]]; then
451-
if [[ $color -eq 0 ]]; then
451+
if (( $color == 0 )); then
452452
bat_args+=(--color=always)
453453
fi
454454
bat_args+=(--paging=never)
@@ -460,7 +460,7 @@ main_with_pager()
460460

461461
case $paging in
462462
auto)
463-
if [[ $nb_files -eq 1 ]]; then
463+
if (( $nb_files == 1 )); then
464464
main
465465
else
466466
if [[ ${pager/ */} = 'less' ]]; then
@@ -470,7 +470,7 @@ case $paging in
470470
fi
471471
;;
472472
always)
473-
if [[ $nb_files -eq 1 ]]; then
473+
if (( $nb_files == 1 )); then
474474
bat_args+=(--paging=always)
475475
main
476476
else

0 commit comments

Comments
 (0)