cat-highlight: Add support for CATOPEN; add example
This commit is contained in:
parent
a7a404fa92
commit
4e1fdfa87e
@ -1,17 +1,27 @@
|
||||
#!/usr/bin/env zsh
|
||||
# Highlight cat output with whatever less is using for highlighting. The command
|
||||
# in $LESSOPEN needs to be able to work with multiple files.
|
||||
# Highlight cat output with either $CATOPEN or $LESSOPEN. The command needs to
|
||||
# have %s in it that will be replaced with all input files. Some programs that
|
||||
# are known to not work will be ignored in $LESSOPEN but not in $CATOPEN.
|
||||
|
||||
# Check if we are in a terminal and $LESSOPEN is not empty
|
||||
if [[ -t 1 && -n "${LESSOPEN}" ]]; then
|
||||
# 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
|
||||
# Example:
|
||||
# export CATOPEN="highlight --force --out-format=truecolor --stdout %s"
|
||||
# alias cat='cat-highlight'
|
||||
|
||||
# Check if we are in a terminal and a highlighter is defined
|
||||
if [[ -t 1 ]] && [[ -n "${CATOPEN}" || -n "${LESSOPEN}" ]]; then
|
||||
if [[ -z "${CATOPEN}" ]]; then
|
||||
# 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
|
||||
local catopen="${LESSOPEN/|/}"
|
||||
else
|
||||
local catopen="${CATOPEN}"
|
||||
fi
|
||||
|
||||
local -a args
|
||||
local -a files
|
||||
@ -24,7 +34,6 @@ if [[ -t 1 && -n "${LESSOPEN}" ]]; then
|
||||
fi
|
||||
done
|
||||
|
||||
local catopen="${LESSOPEN/|/}"
|
||||
eval "${catopen/\%s/${files}} | \cat ${args}"
|
||||
else
|
||||
\cat "${@}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user