Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bat colorization and robust config file detection #158

Merged
merged 4 commits into from
Sep 22, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=$(bat --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%%[|&;<>]*}")
[[ -n $style ]] && opt+=(--style="${style%% *}")
[[ -n $theme ]] && opt+=(--theme="${theme%%[|&;<>]*}")
suvayu marked this conversation as resolved.
Show resolved Hide resolved
opt+=("$COLOR" --paging=never "$1") ;;
pygmentize)
pygmentize -l "$lang" /dev/null &>/dev/null && opt=(-l "$lang") || opt=(-g)
Expand Down