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.

44 lines
540 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. if [ -z "$PAGER" ]; then
  13. PAGER=cat
  14. fi
  15. else
  16. PAGER="less -R"
  17. fi
  18. else
  19. PAGER=cat
  20. fi
  21. for f; do
  22. l=
  23. eval t=$(file -i - < "$f" | cut -d' ' -f2-)
  24. case "$t" in
  25. application/xml)
  26. l=xml
  27. ;;
  28. text/x-shellscript)
  29. l=sh
  30. ;;
  31. esac
  32. pygmentize ${l:+-l $l} "$f"
  33. done | $PAGER
  34. if [ -n "$tmp_f" ]; then
  35. rm -f "$tmp_f"
  36. fi