Closed iceblock-coder closed 2 years ago
Updated: In previous workaround, when a non .tgz file(e.g a .gz compessed log file) comes, pygmentize guesses again. So I decide to escape guess at all.
diff --git a/lesspipe.sh b/lesspipe.sh
index 4569e5c..88142eb 100755
--- a/lesspipe.sh
+++ b/lesspipe.sh
@@ -390,7 +390,7 @@ has_colorizer () {
opt="$opt $COLOR" ;;
pygmentize)
[[ -n $LESSCOLORIZER && $LESSCOLORIZER =~ pygmentize\ \ *-O\ *style=[a-z]* ]] && prog=$LESSCOLORIZER
- res=$(pygmentize -l $2 /dev/null 2>/dev/null) && opt=" -l $2" || opt=" -g" ;;
+ res=$(pygmentize -l $2 /dev/null 2>/dev/null) && opt=" -l $2" || return ;;
source-highlight)
prog="source-highlight --failsafe -f esc"
[[ -z $arg ]] && arg=/dev/stdin
Original: My current approach is to add an escape for tar.
diff --git a/lesspipe.sh b/lesspipe.sh
index 105ccd5..0d59914 100755
--- a/lesspipe.sh
+++ b/lesspipe.sh
@@ -215,7 +215,7 @@ show () {
if [[ "$cmd" != "" ]]; then
show "-$rest1"
else
- isfinal "$ft" "$file1" "$rest11"
+ isfinal "$ft" "$file1" "$rest11" ''
fi
elif [[ "$c1" == "" ]]; then
c1=("${cmd[@]}")
@@ -224,7 +224,7 @@ show () {
if [[ "$cmd" != "" ]]; then
show "-$rest1"
else
- "${c1[@]}" | isfinal "$ft" - "$rest11"
+ "${c1[@]}" | isfinal "$ft" - "$rest11" "${c1[0]}"
fi
elif [[ "$c2" == "" ]]; then
c2=("${cmd[@]}")
@@ -233,7 +233,7 @@ show () {
if [[ "$cmd" != "" ]]; then
show "-$rest1"
else
- "${c1[@]}" | "${c2[@]}" | isfinal "$ft" - "$rest11"
+ "${c1[@]}" | "${c2[@]}" | isfinal "$ft" - "$rest11" "${c2[0]}"
fi
elif [[ "$c3" == "" ]]; then
c3=("${cmd[@]}")
@@ -242,7 +242,7 @@ show () {
if [[ "$cmd" != "" ]]; then
show "-$rest1"
else
- "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | isfinal "$ft" - "$rest11"
+ "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | isfinal "$ft" - "$rest11" "${c3[0]}"
fi
elif [[ "$c4" == "" ]]; then
c4=("${cmd[@]}")
@@ -251,7 +251,7 @@ show () {
if [[ "$cmd" != "" ]]; then
show "-$rest1"
else
- "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | isfinal "$ft" - "$rest11"
+ "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | isfinal "$ft" - "$rest11" "${c4[0]}"
fi
elif [[ "$c5" == "" ]]; then
c5=("${cmd[@]}")
@@ -260,7 +260,7 @@ show () {
if [[ "$cmd" != "" ]]; then
echo "$0: Too many levels of encapsulation"
else
- "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | "${c5[@]}" | isfinal "$ft" - "$rest11"
+ "${c1[@]}" | "${c2[@]}" | "${c3[@]}" | "${c4[@]}" | "${c5[@]}" | isfinal "$ft" - "$rest11" "${c5[0]}"
fi
fi
}
@@ -371,9 +371,21 @@ has_colorizer () {
arg="$1"
[[ "$arg" = - ]] && arg=
[[ $COLOR == *always ]] || return
- [[ $2 == plain || -z $2 ]] && return
+ if [[ $2 == plain || -z $2 ]] && [[ $3 != istar ]]
+ then
+ return
+ fi
prog=${LESSCOLORIZER%% *}
+ if [[ $3 == istar ]] ; then
+ if has_cmd tarcolor; then
+ echo tarcolor
+ else
+ echo cat
+ fi
+ return
+ fi
+
for i in bat batcat pygmentize source-highlight code2color vimcolor ; do
[[ -z $prog || $prog == $i ]] && has_cmd $i && prog=$i
done
@@ -535,7 +547,7 @@ isfinal () {
[[ -n "$file2" ]] && fext="$file2"
[[ -z "$fext" && $fcat == text && $x != plain ]] && fext=$x
[[ -z "$fext" ]] && fext=$(fileext "$fileext")
- colorizer=$(has_colorizer "$2" "$fext")
+ colorizer=$(has_colorizer "$2" "$fext" "$4")
if [[ -n $colorizer && $fcat != binary ]]; then
$colorizer && return
fi
@@ -549,8 +561,8 @@ istar () {
[[ "$2" =~ ^[a-z_-]*:.* ]] && echo $2: remote operation tar host:file not allowed && return
if [[ -n $3 ]]; then
$prog Oxf "$2" "$3" 2>&1
- elif [[ $COLOR == *always ]] && has_cmd tarcolor; then
- $prog tvf "$2" | tarcolor
+# elif [[ $COLOR == *always ]] && has_cmd tarcolor; then
+# $prog tvf "$2" | tarcolor
else
$prog tvf "$2"
fi
Archive listings are now colored using archive_color (slightly modified tarcolor). They are no longer handed to another colorizer.
Hello,
Trying to less some log files which are fastened in a tgz. Although tarcolor is tested positive, pygmentize is still kicked-in to guess colorizing the output. Which causes the output weird.
** Just tar:
** Less:
** Full debug log: