Make cat-highlight work with multiple files
This commit is contained in:
parent
9f90c6c8ed
commit
1a1afe2419
|
@ -28,14 +28,26 @@ function export-emacs
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Highlight cat output with whatever less is using for highlighting
|
# 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()
|
function cat-highlight()
|
||||||
{
|
{
|
||||||
# Check if we are in a terminal and $LESSOPEN is not empty
|
# Check if we are in a terminal and $LESSOPEN is not empty
|
||||||
if [[ -t 1 && -n "${LESSOPEN}" ]]; then
|
if [[ -t 1 && -n "${LESSOPEN}" ]]; then
|
||||||
# Works only if command understands - as stdin
|
local -a args
|
||||||
CATOPEN="${LESSOPEN/\%s/-}"
|
local -a files
|
||||||
eval "\cat $@ ${CATOPEN}"
|
for arg in $@; do
|
||||||
|
# Filter out file names
|
||||||
|
if [[ "${arg:0:1}" != "-" ]]; then
|
||||||
|
files+="$arg"
|
||||||
|
else
|
||||||
|
args+="$arg"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
local catopen="${LESSOPEN/| /}"
|
||||||
|
catopen="${catopen/\%s/${files}}"
|
||||||
|
eval "${catopen} | \cat ${args}"
|
||||||
else
|
else
|
||||||
\cat $@
|
\cat $@
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue