cat-highlight: Fix infinite loop, check if $LESSOPEN is set

This commit is contained in:
tastytea 2022-03-18 16:12:44 +01:00
parent 224b12ffa6
commit 283971e3ad
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM

View File

@ -31,11 +31,12 @@ function export-emacs
# Highlight cat output with whatever less is using for highlighting
function cat-highlight()
{
if [[ -t 1 ]]; then # We're in a terminal
# Check if we are in a terminal and $LESSOPEN is not empty
if [[ -t 1 && -n "${LESSOPEN}" ]]; then
CATOPEN="${LESSOPEN/| }"
CATOPEN="${CATOPEN/ %s}"
cat $@ | eval ${CATOPEN}
\cat $@ | eval ${CATOPEN}
else
cat $@
\cat $@
fi
}