1
0
Fork 0
dotfiles/.lessfilter

37 lines
1.0 KiB
Bash
Executable File

#!/bin/zsh
# Try to use highlight. If that fails or the output looks suspicious, use
# lesspipe normally.
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
local file="${1}"
local ret
local output
if type highlight >& -; then
output="$(highlight --force \
--out-format=truecolor \
--style=base16/unikitty-reversible \
--stdout "${file}")"
ret=${?}
elif type pygmentize >& -; then
output="$(pygmentize -f terminal16m -g -O style=paraiso-dark ${file})"
ret=${?}
elif type source-highlight >& -; then
output="$(source-highlight --failsafe \
--infer-lang \
--out-format=esc \
--style-file=esc.style \
--input=${file})"
ret=${?}
fi
[[ ${ret} -eq 0 ]] || return ${ret}
# Try to catch when the output is just the magic string
zmodload zsh/stat
if [[ ${#output} -lt 256 && $(zstat +size "${file}") -gt 256 ]]; then
return 1
fi
print -r ${output}