1
0
Fork 0

Add ~/.lessfilter

This commit is contained in:
tastytea 2022-03-22 23:36:12 +01:00
parent 767ad1794a
commit 77553ac29d
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
2 changed files with 22 additions and 1 deletions

View File

@ -83,7 +83,8 @@ export PASSWORD_STORE_GENERATED_LENGTH="43"
export LESS="--tabs=4 --RAW-CONTROL-CHARS --LONG-PROMPT"
if command -v highlight > /dev/null; then
LESSOPEN="| $(command -v highlight) --force --out-format=truecolor --style=base16/unikitty-reversible --stdout %s"
# ~/.lessfilter handles the highlighting
LESSOPEN="| $(command -v lesspipe) %s"
elif command -v pygmentize > /dev/null; then
LESSOPEN="| $(command -v pygmentize) -f terminal16m -g -O style=paraiso-dark %s"
elif command -v source-highlight > /dev/null; then

20
.lessfilter Executable file
View File

@ -0,0 +1,20 @@
#!/bin/zsh
# Try to use highlight. If that fails or the output looks suspicious, use
# lesspipe normally.
command -v highlight > /dev/null || return 1
file="${1}"
local output="$(highlight --validate-input \
--force \
--out-format=truecolor \
--style=base16/unikitty-reversible \
--stdout "${file}")"
[[ ${?} -eq 0 ]] || return 1
# Try to catch when the output is just the magic string
if [[ ${#output} -lt 256 && $(stat --printf="%s" "${file}") -gt 256 ]]; then
return 1
fi
print "${output}"