Skip to content

Commit

Permalink
replace arithmetic comparisons of the form [[ ... ]] with (( ... ))
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpoelen committed May 28, 2023
1 parent 670d62f commit 6f1ac07
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions batrg
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ for ((i=1,ie=$#batrg_args; i <= ie; ++i)) ; do
esac
done

if [[ $positional_pattern -eq 1 ]] && [[ $# -eq 0 ]]; then
if (( $positional_pattern == 1 && $# == 0 )); then
help
exit 2
fi
Expand All @@ -279,41 +279,41 @@ else
terminal_width=
fi

if [[ $#file_separator -eq 1 ]]; then
if (( $#file_separator == 1 )); then
if [[ -n $terminal_width ]]; then
file_separator=${${(l:$terminal_width:: :)''}// /"$file_separator"}$'\n'
else
file_separator=
fi
fi

if [[ $style -eq 0 ]] && [[ -z $BAT_STYLE ]]; then
if [[ $snip -eq 2 ]]; then
if [[ $ctx_after -eq 0 ]] && [[ $ctx_before -eq 0 ]]; then
if (( $style == 0 )) && [[ -z $BAT_STYLE ]]; then
if (( $snip == 2 )); then
if (( $ctx_after == 0 && $ctx_before == 0 )); then
snip=0
else
# --style=snip since bat-0.12
bat_version=$($=bat_engine --version)
setopt extendedglob
if [[ $bat_version = 'bat '(#b)(<0-9>##).(<0-9>##)* ]] &&
[[ ${bat_version[$mbegin[1],$mend[1]]} = 0 ]] &&
[[ ${bat_version[$mbegin[2],$mend[2]]} -lt 12 ]] ;
(( ${bat_version[$mbegin[2],$mend[2]]} < 12 )) ;
then
snip=0
fi
setopt noextendedglob
fi
fi

if [[ $snip -eq 0 ]]; then
if (( $snip == 0 )); then
bat_args+=(--style=numbers,header)
else
bat_args+=(--style=numbers,header,snip)
fi
fi

if [[ $highlight -eq 2 ]]; then
if [[ $ctx_after -eq 0 ]] && [[ $ctx_before -eq 0 ]]; then
if (( $highlight == 2 )); then
if (( $ctx_after == 0 && $ctx_before == 0 )); then
highlight=0
else
highlight=1
Expand All @@ -324,7 +324,7 @@ fi
temp_files=()
remove_temps()
{
if [[ $#temp_files -ne 0 ]]; then
if (( $#temp_files != 0 )); then
rm -- $temp_files
fi
}
Expand All @@ -340,7 +340,7 @@ if [[ $@[$i] = '--' ]] ; then
rg_args+=(--)
fi

if [[ $positional_pattern -eq 1 ]]; then
if (( $positional_pattern == 1 )); then
rg_args+=($@[$file_index])
((++file_index))
fi
Expand All @@ -358,20 +358,20 @@ for ((i=1,ie=$#files; i <= $ie; ++i)) ; do
<$files[$i] >$tmp
fi
files[$i]=$tmp
elif [[ $files[$i] = '--' ]] && [[ $has_sep -eq 0 ]]; then
elif [[ $files[$i] = '--' ]] && (( $has_sep == 0 )); then
((--nb_files))
has_sep=1
fi
((++nb_files))
done

if [[ $nb_files -eq 0 ]] && [[ ! -t 0 ]]; then
if (( $nb_files == 0 )) && [[ ! -t 0 ]]; then
tmp=${BATRG_PREFIX}stdin
temp_files+=($tmp)
files+=($tmp)
nb_files=1
<&0 >$tmp
elif [[ $nb_files -eq 1 ]] && [[ -d $files ]] ; then
elif (( $nb_files == 1 )) && [[ -d $files ]] ; then
nb_files=2 # assume there is more than 1 file
fi

Expand All @@ -393,9 +393,9 @@ main()

run_bat()
{
[[ $found -ne 0 ]] && echo -nE $file_separator
(( $found != 0 )) && echo -nE $file_separator
first_line=$(($first_line-$ctx_before))
[[ $first_line -gt 0 ]] || first_line=
(( $first_line > 0 )) || first_line=
curr_bat_args[1]='--line-range='$first_line':'$(($prev_line+$ctx_after))
$=bat_engine $bat_args $curr_bat_args -- $filename
found=2
Expand All @@ -421,24 +421,24 @@ main()
break
fi

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

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

prev_line=$line
done
done

if [[ $prev_line -ne -1 ]]; then
if (( $prev_line != -1 )); then
run_bat
[[ $file_separator_wrap -eq 1 ]] && echo -nE $file_separator
(( $file_separator_wrap == 1 )) && echo -nE $file_separator
fi
}

Expand All @@ -448,7 +448,7 @@ main()
main_with_pager()
{
if [[ -t 1 ]]; then
if [[ $color -eq 0 ]]; then
if (( $color == 0 )); then
bat_args+=(--color=always)
fi
bat_args+=(--paging=never)
Expand All @@ -460,7 +460,7 @@ main_with_pager()

case $paging in
auto)
if [[ $nb_files -eq 1 ]]; then
if (( $nb_files == 1 )); then
main
else
if [[ ${pager/ */} = 'less' ]]; then
Expand All @@ -470,7 +470,7 @@ case $paging in
fi
;;
always)
if [[ $nb_files -eq 1 ]]; then
if (( $nb_files == 1 )); then
bat_args+=(--paging=always)
main
else
Expand Down

0 comments on commit 6f1ac07

Please sign in to comment.