dotfiles/.config/zsh/functions/cat-highlight

26 lines
704 B
Plaintext
Raw Normal View History

# -*- mode: shell-script; -*-
# Highlight cat output with whatever less is using for highlighting. The command
# in $LESSOPEN needs to be able to work with multiple files.
function cat-highlight()
{
# Check if we are in a terminal and $LESSOPEN is not empty
if [[ -t 1 && -n "${LESSOPEN}" ]]; then
local -a args
local -a files
for arg in "${@}"; do
# Filter out file names
if [[ "${arg[1]}" != "-" ]]; then
files+="${arg}"
else
args+="${arg}"
fi
done
local catopen="${LESSOPEN/|/}"
eval "${catopen/\%s/${files}} | \cat ${args}"
else
\cat "${@}"
fi
}