Zsh: Add cat-highlight function

This commit is contained in:
tastytea 2022-03-18 16:01:01 +01:00
parent bf5f9bad52
commit 224b12ffa6
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
2 changed files with 14 additions and 0 deletions

View File

@ -78,6 +78,8 @@ alias ip='ip -color -brief'
# Add --accept=".jpg,.png" or whatever.
alias wget_leech='wget --no-directories --page-requisites --span-hosts'
alias cat='cat-highlight'
# OS specific settings.
case $(lsb_release -i -s 2> /dev/null) in
Gentoo)

View File

@ -27,3 +27,15 @@ function export-emacs
emacsclient -e "(setenv \"${name}\" \"${value}\")" >/dev/null
done
}
# Highlight cat output with whatever less is using for highlighting
function cat-highlight()
{
if [[ -t 1 ]]; then # We're in a terminal
CATOPEN="${LESSOPEN/| }"
CATOPEN="${CATOPEN/ %s}"
cat $@ | eval ${CATOPEN}
else
cat $@
fi
}