Skip to content

Commit

Permalink
Merge pull request #158 from suvayu/bat-colorize
Browse files Browse the repository at this point in the history
Fix `bat` colorization and robust config file detection
  • Loading branch information
wofr06 authored Sep 22, 2024
2 parents 3188109 + 19abff7 commit 535826a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lesspipe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -437,23 +437,25 @@ has_colorizer () {
[[ -n $3 ]] && lang=$3 || lang=$2
case $prog in
bat|batcat)
batconfig=$($prog --config-file)
[[ -n $lang ]] && $prog --list-languages|sed 's/.*:/,/;s/$/,/'|grep -i ",$lang," > /dev/null && opt=(-l "$lang")
[[ -n $LESSCOLORIZER && $LESSCOLORIZER = *\ *--style=* ]] && style="${LESSCOLORIZER/* --style=/}"
[[ -z $style ]] && style=$BAT_STYLE
[[ -n $LESSCOLORIZER && $LESSCOLORIZER = *\ *--theme=* ]] && theme="${LESSCOLORIZER/* --theme=/}"
[[ -z $theme ]] && theme=$BAT_THEME
if [[ -r "$HOME/.config/bat/config" ]]; then
if [[ -r "$batconfig" ]]; then
if [[ -z $style ]]; then
grep -q -e '^--style' "$HOME/.config/bat/config" || style=plain
grep -q -e '^--style' "$batconfig" || style=plain
fi
if [[ -z $theme ]]; then
grep -q -e '^--theme' "$HOME/.config/bat/config" || theme=ansi
grep -q -e '^--theme' "$batconfig" || theme=ansi
fi
else
[[ -z $style ]] && style=plain
[[ -z $theme ]] && theme=ansi
fi
opt+=(--style="${style%% *}" --theme="${theme%%[|&;<>]*}")
style="${style%% *}" theme="${theme%%[|&;<>]*}"
opt+=(${style:+--style="$style"} ${theme:+--theme="$theme"})
opt+=("$COLOR" --paging=never "$1") ;;
pygmentize)
pygmentize -l "$lang" /dev/null &>/dev/null && opt=(-l "$lang") || opt=(-g)
Expand Down

0 comments on commit 535826a

Please sign in to comment.