Skip to content

Commit

Permalink
prefer bat styles/themes from ENV or command line over config file va…
Browse files Browse the repository at this point in the history
…lues
  • Loading branch information
wofr06 committed May 22, 2024
1 parent 99f9d98 commit 52fa399
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
****************************************************************************
# ChangeLog for lesspipe.sh #
****************************************************************************
- prefer bat styles and themes from ENV or command line over config file
Version 2.13 May 10 2024
- added support for appimage and snap files
- respect color scheme setting of vim in vimcolor, add listing of file types
Expand Down
16 changes: 9 additions & 7 deletions lesspipe.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# lesspipe.sh, a preprocessor for less
lesspipe_version=2.13
lesspipe_version=2.12
# Author: Wolfgang Friebel (wp.friebel AT gmail.com)

has_cmd () {
Expand Down Expand Up @@ -440,16 +440,18 @@ has_colorizer () {
[[ -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
[[ -z $style ]] && style=plain
[[ -n $LESSCOLORIZER && $LESSCOLORIZER = *\ *--theme=* ]] && theme="${LESSCOLORIZER/* --theme=/}"
[[ -z $theme ]] && theme=$BAT_THEME
[[ -z $theme ]] && theme=ansi
if [[ -r "$HOME/.config/bat/config" ]]; then
grep -q -e '^--style' "$HOME/.config/bat/config" || opt+=(--style="${style%% *}")
grep -q -e '^--theme' "$HOME/.config/bat/config" || opt+=(--theme="${theme%% *}")
else
opt+=(--style="${style%% *}" --theme="${theme%% *}")
if [[ -z $style ]]; then
grep -q -e '^--style' "$HOME/.config/bat/config" || style=plain
fi
if [[ -z $theme ]]; then
grep -q -e '^--theme' "$HOME/.config/bat/config" || theme=ansi
fi
fi
[[ -n $style ]] && opt+=(--style="${style%% *}")
[[ -n $theme ]] && opt+=(--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 52fa399

Please sign in to comment.