dotfiles/.lessfilter

24 lines
628 B
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
command -v highlight > /dev/null
file="${1}"
local output="$(highlight --force \
--out-format=truecolor \
--style=base16/unikitty-reversible \
--stdout "${file}")"
ret=${?}
[[ ${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}