diff --git a/.config/zsh/functions.zsh b/.config/zsh/functions.zsh index b9b30ff..8e9e69e 100644 --- a/.config/zsh/functions.zsh +++ b/.config/zsh/functions.zsh @@ -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