Make cat-highlight work with multiple files
This commit is contained in:
parent
9f90c6c8ed
commit
1a1afe2419
@ -28,14 +28,26 @@ function export-emacs
|
||||
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()
|
||||
{
|
||||
# Check if we are in a terminal and $LESSOPEN is not empty
|
||||
if [[ -t 1 && -n "${LESSOPEN}" ]]; then
|
||||
# Works only if command understands - as stdin
|
||||
CATOPEN="${LESSOPEN/\%s/-}"
|
||||
eval "\cat $@ ${CATOPEN}"
|
||||
local -a args
|
||||
local -a files
|
||||
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
|
||||
\cat $@
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user