2022-03-19 04:34:14 +01:00
|
|
|
#!/usr/bin/env zsh
|
2022-03-19 03:54:51 +01:00
|
|
|
# Highlight cat output with whatever less is using for highlighting. The command
|
|
|
|
# in $LESSOPEN needs to be able to work with multiple files.
|
|
|
|
|
2022-03-19 04:34:14 +01:00
|
|
|
# Check if we are in a terminal and $LESSOPEN is not empty
|
|
|
|
if [[ -t 1 && -n "${LESSOPEN}" ]]; then
|
2022-03-20 00:26:38 +01:00
|
|
|
# Programs that won't work with cat
|
|
|
|
local -a known_bad=("lesspipe")
|
|
|
|
for baddy in ${known_bad}; do
|
|
|
|
if [[ "${LESSOPEN}" =~ "${baddy}" ]]; then
|
|
|
|
\cat "${@}"
|
|
|
|
return ${?}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-03-19 04:34:14 +01:00
|
|
|
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
|