You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
532 B

  1. #!/bin/sh
  2. exec 2>&1
  3. tmp_f=
  4. if [ $# -eq 0 ]; then
  5. tmp_f="${TMPDIR:-/tmp}/colorize.$$"
  6. trap "rm -f '$tmp_f'" INT TERM
  7. cat > "$tmp_f"
  8. set -- "$tmp_f"
  9. fi
  10. if [ -t 1 ]; then
  11. if env | grep -q '^PAGER=$'; then
  12. PAGER=cat
  13. elif [ -z "$PAGER" ]; then
  14. PAGER="less -R"
  15. fi
  16. else
  17. PAGER=cat
  18. fi
  19. for f; do
  20. l=
  21. eval t=$(file -i - < "$f" | cut -d' ' -f2-)
  22. case "$t" in
  23. application/xml)
  24. l=xml
  25. ;;
  26. text/x-shellscript)
  27. l=sh
  28. ;;
  29. esac
  30. pygmentize ${l:+-l $l} "$f"
  31. done | $PAGER
  32. if [ -n "$tmp_f" ]; then
  33. rm -f "$tmp_f"
  34. fi