#!/bin/sh exec 2>&1 tmp_f= if [ $# -eq 0 ]; then tmp_f="${TMPDIR:-/tmp}/colorize.$$" trap "rm -f '$tmp_f'" INT TERM cat > "$tmp_f" set -- "$tmp_f" fi if [ -t 1 ]; then if env | grep -q '^PAGER=$'; then PAGER=cat elif [ -z "$PAGER" ]; then PAGER="less -R" fi else PAGER=cat fi for f; do l= eval mime=$(file -i -L - < "$f" | cut -d' ' -f2-) case "$mime" in application/xml) l=xml ;; text/x-shellscript) l=sh ;; text/x-diff) l=diff ;; text/x-c) l=c ;; text/plain) case "$(file - < "$f" | cut -d' ' -f2-)" in a\ */python\ script) l=python ;; *) case "$f" in *.sh) l=sh ;; *.ini) l=ini ;; *.c|*.h|*.cc|*.hh) l=c ;; *.go) l=go ;; *) l=text ;; esac ;; esac esac pygmentize ${l:+-l $l} "$f" done | $PAGER if [ -n "$tmp_f" ]; then rm -f "$tmp_f" fi