1
0
Fork 0
dotfiles/.lessfilter

24 lines
627 B
Plaintext
Raw Normal View History

2022-03-22 23:36:12 +01:00
#!/bin/zsh
# Try to use highlight. If that fails or the output looks suspicious, use
# lesspipe normally.
2022-04-14 23:37:56 +02:00
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
command -v highlight > /dev/null
2022-03-22 23:36:12 +01:00
file="${1}"
local output="$(highlight --force \
2022-03-22 23:36:12 +01:00
--out-format=truecolor \
--style=base16/unikitty-reversible \
--stdout "${file}")"
2022-04-14 23:37:56 +02:00
ret=${?}
[[ ${ret} -eq 0 ]] || return ${ret}
2022-03-22 23:36:12 +01:00
# Try to catch when the output is just the magic string
2022-04-14 23:37:56 +02:00
zmodload zsh/stat
if [[ ${#output} -lt 256 && $(zstat +size "${file}") -gt 256 ]]; then
2022-03-22 23:36:12 +01:00
return 1
fi
print "${output}"